-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdprocess.pas
709 lines (623 loc) · 23.6 KB
/
dprocess.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
{ Freepascal TProcess ported to Delphi
License: FPC Modified LGPL (can use in commercial apps)
Changes to the code marked with "L505" in comments }
{
This file is part of the Free Component Library (FCL)
Copyright (c) 1999-2000 by the Free Pascal development team
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
unit dprocess;
interface
uses
classes,
dpipes, // L505
system.types,//L505
sysutils;
Type
TProcessOption = (poRunSuspended,poWaitOnExit,
poUsePipes,poStderrToOutPut,
poNoConsole,poNewConsole,
poDefaultErrorMode,poNewProcessGroup,
poDebugProcess,poDebugOnlyThisProcess);
TShowWindowOptions = (swoNone,swoHIDE,swoMaximize,swoMinimize,swoRestore,swoShow,
swoShowDefault,swoShowMaximized,swoShowMinimized,
swoshowMinNOActive,swoShowNA,swoShowNoActivate,swoShowNormal);
TStartupOption = (suoUseShowWindow,suoUseSize,suoUsePosition,
suoUseCountChars,suoUseFillAttribute);
TProcessPriority = (ppHigh,ppIdle,ppNormal,ppRealTime);
TProcessOptions = set of TProcessOption;
TStartupOptions = set of TStartupOption;
Type
{$ifdef MACOS} //L505
TProcessForkEvent = procedure(Sender : TObject) of object;
{$endif}
{ TProcess }
TProcess = Class (TComponent)
Private
FProcessOptions : TProcessOptions;
FStartupOptions : TStartupOptions;
FProcessID : Integer;
FTerminalProgram: String;
FThreadID : Integer;
FProcessHandle : Thandle;
FThreadHandle : Thandle;
FFillAttribute : Cardinal;
FApplicationName : string;
FConsoleTitle : String;
FCommandLine : String;
FCurrentDirectory : String;
FDesktop : String;
FEnvironment : Tstrings;
FExecutable : String;
FParameters : TStrings;
FShowWindow : TShowWindowOptions;
FInherithandles : Boolean;
{$ifdef MACOS} // L505
FForkEvent : TProcessForkEvent;
{$endif}
FProcessPriority : TProcessPriority;
dwXCountchars,
dwXSize,
dwYsize,
dwx,
dwYcountChars,
dwy : Cardinal;
FXTermProgram: String;
FPipeBufferSize : cardinal;
Procedure FreeStreams;
Function GetExitStatus : Integer;
Function GetExitCode : Integer;
Function GetRunning : Boolean;
Function GetWindowRect : TRect;
procedure SetCommandLine(const AValue: String);
procedure SetParameters(const AValue: TStrings);
Procedure SetWindowRect (Value : TRect);
Procedure SetShowWindow (Value : TShowWindowOptions);
Procedure SetWindowColumns (Value : Cardinal);
Procedure SetWindowHeight (Value : Cardinal);
Procedure SetWindowLeft (Value : Cardinal);
Procedure SetWindowRows (Value : Cardinal);
Procedure SetWindowTop (Value : Cardinal);
Procedure SetWindowWidth (Value : Cardinal);
procedure SetApplicationName(const Value: String);
procedure SetProcessOptions(const Value: TProcessOptions);
procedure SetActive(const Value: Boolean);
procedure SetEnvironment(const Value: TStrings);
Procedure ConvertCommandLine;
function PeekExitStatus: Boolean;
Protected
FRunning : Boolean;
FExitCode : Cardinal;
FInputStream : TOutputPipeStream;
FOutputStream : TInputPipeStream;
FStderrStream : TInputPipeStream;
procedure CloseProcessHandles; virtual;
Procedure CreateStreams(InHandle,OutHandle,ErrHandle : Longint);virtual;
procedure FreeStream(var AStream: THandleStream);
procedure Loaded; override;
Public
Constructor Create (AOwner : TComponent);override;
Destructor Destroy; override;
Procedure Execute; virtual;
procedure CloseInput; virtual;
procedure CloseOutput; virtual;
procedure CloseStderr; virtual;
Function Resume : Integer; virtual;
Function Suspend : Integer; virtual;
Function Terminate (AExitCode : Integer): Boolean; virtual;
Function WaitOnExit : Boolean;
Property WindowRect : Trect Read GetWindowRect Write SetWindowRect;
Property Handle : THandle Read FProcessHandle;
Property ProcessHandle : THandle Read FProcessHandle;
Property ThreadHandle : THandle Read FThreadHandle;
Property ProcessID : Integer Read FProcessID;
Property ThreadID : Integer Read FThreadID;
Property Input : TOutputPipeStream Read FInputStream;
Property Output : TInputPipeStream Read FOutputStream;
Property Stderr : TinputPipeStream Read FStderrStream;
Property ExitStatus : Integer Read GetExitStatus;
Property ExitCode : Integer Read GetExitCode;
Property InheritHandles : Boolean Read FInheritHandles Write FInheritHandles;
{$ifdef MACOS} // L505
property OnForkEvent : TProcessForkEvent Read FForkEvent Write FForkEvent;
{$endif}
Published
property PipeBufferSize : cardinal read FPipeBufferSize write FPipeBufferSize default 1024;
Property Active : Boolean Read GetRunning Write SetActive;
Property ApplicationName : String Read FApplicationName Write SetApplicationName; //deprecated; //L505
Property CommandLine : String Read FCommandLine Write SetCommandLine ; //deprecated; //L505
Property Executable : String Read FExecutable Write FExecutable;
Property Parameters : TStrings Read FParameters Write SetParameters;
Property ConsoleTitle : String Read FConsoleTitle Write FConsoleTitle;
Property CurrentDirectory : String Read FCurrentDirectory Write FCurrentDirectory;
Property Desktop : String Read FDesktop Write FDesktop;
Property Environment : TStrings Read FEnvironment Write SetEnvironment;
Property Options : TProcessOptions Read FProcessOptions Write SetProcessOptions;
Property Priority : TProcessPriority Read FProcessPriority Write FProcessPriority;
Property StartupOptions : TStartupOptions Read FStartupOptions Write FStartupOptions;
Property Running : Boolean Read GetRunning;
Property ShowWindow : TShowWindowOptions Read FShowWindow Write SetShowWindow;
Property WindowColumns : Cardinal Read dwXCountChars Write SetWindowColumns;
Property WindowHeight : Cardinal Read dwYSize Write SetWindowHeight;
Property WindowLeft : Cardinal Read dwX Write SetWindowLeft;
Property WindowRows : Cardinal Read dwYCountChars Write SetWindowRows;
Property WindowTop : Cardinal Read dwY Write SetWindowTop ;
Property WindowWidth : Cardinal Read dwXSize Write SetWindowWidth;
Property FillAttribute : Cardinal read FFillAttribute Write FFillAttribute;
Property XTermProgram : String Read FXTermProgram Write FXTermProgram;
end;
EProcess = Class(Exception);
Procedure CommandToList(S : String; List : TStrings);
{$ifdef MACOS} //L505
Var
TryTerminals : Array of string;
XTermProgram : String;
Function DetectXTerm : String;
{$endif}
{ // L505: changed to ansistring
function RunCommandIndir(const curdir:string;const exename:string;const commands:array of string;out outputstring:string; out exitstatus:integer; Options : TProcessOptions = []):integer; overload; //L505
function RunCommandIndir(const curdir:string;const exename:string;const commands:array of string;out outputstring:string; Options : TProcessOptions = []):boolean; overload; // L505
function RunCommand(const exename:string;const commands:array of string;out outputstring:string; Options : TProcessOptions = []):boolean; overload;// L505
function RunCommandInDir(const curdir,cmdline:string;out outputstring:string):boolean; deprecated; overload; // L505
function RunCommand(const cmdline:string;out outputstring:string):boolean; deprecated; overload; // L505
}
function RunCommandIndir(const curdir: string; const exename: string; const commands: array of string; out outputstring: ansistring; out exitstatus:integer; Options : TProcessOptions = []):integer; overload; //L505
function RunCommandIndir(const curdir: string; const exename: string; const commands: array of string; out outputstring: ansistring; Options : TProcessOptions = []):boolean; overload; // L505
function RunCommand(const exename: string; const commands: array of string; out outputstring: ansistring; Options : TProcessOptions = []):boolean; overload;// L505
function RunCommandInDir(const curdir,cmdline:string;out outputstring:ansistring):boolean; deprecated; overload; // L505
function RunCommand(const cmdline:string;out outputstring:ansistring):boolean; deprecated; overload; // L505
implementation
{$IFDEF MACOS} //L505
{$i process_macos.inc}
{$ENDIF}
{$IFDEF MSWINDOWS} //L505
{$i process_win.inc}
{$ENDIF}
Procedure CommandToList(S : String; List : TStrings);
Function GetNextWord : String;
Const
WhiteSpace = [' ',#9,#10,#13];
Literals = ['"',''''];
Var
Wstart,wend : Integer;
InLiteral : Boolean;
LastLiteral : char;
begin
WStart:=1;
// L505 change "in" to CharInSet
While (WStart<=Length(S)) and (CharInSet(S[WStart], WhiteSpace)) do
Inc(WStart);
WEnd:=WStart;
InLiteral:=False;
LastLiteral:=#0;
// L505
// While (Wend<=Length(S)) and (Not (S[Wend] in WhiteSpace) or InLiteral) do
While (Wend<=Length(S)) and (Not (CharInSet(S[Wend], WhiteSpace)) or InLiteral) do
begin
// L505 changed "in" to CharInSet
if CharInSet(S[Wend], Literals) then
If InLiteral then
InLiteral:=Not (S[Wend]=LastLiteral)
else
begin
InLiteral:=True;
LastLiteral:=S[Wend];
end;
inc(wend);
end;
Result:=Copy(S,WStart,WEnd-WStart);
// L505 changed "in" to CharInSet
if (Length(Result) > 0)
and (Result[1] = Result[Length(Result)]) // if 1st char = last char and..
and (CharInSet(Result[1], Literals)) then // it's one of the literals, then
Result:=Copy(Result, 2, Length(Result) - 2); //delete the 2 (but not others in it)
// L505
// While (WEnd<=Length(S)) and (S[Wend] in WhiteSpace) do
While (WEnd<=Length(S)) and (CharInSet(S[Wend], WhiteSpace)) do
inc(Wend);
Delete(S,1,WEnd-1);
end;
Var
W : String;
begin
While Length(S)>0 do
begin
W:=GetNextWord;
If (W<>'') then
List.Add(W);
end;
end;
Constructor TProcess.Create (AOwner : TComponent);
begin
Inherited;
FProcessPriority:=ppNormal;
FShowWindow:=swoNone;
FInheritHandles:=True;
{$ifdef MACOS} // L505
FForkEvent:=nil;
{$endif}
FPipeBufferSize := 1024;
FEnvironment:=TStringList.Create;
FParameters:=TStringList.Create;
end;
Destructor TProcess.Destroy;
begin
FParameters.Free;
FEnvironment.Free;
FreeStreams;
CloseProcessHandles;
Inherited Destroy;
end;
Procedure TProcess.FreeStreams;
begin
If FStderrStream<>FOutputStream then
FreeStream(THandleStream(FStderrStream));
FreeStream(THandleStream(FOutputStream));
FreeStream(THandleStream(FInputStream));
end;
Function TProcess.GetExitStatus : Integer;
begin
GetRunning;
Result:=FExitCode;
end;
{$IFNDEF OS_HASEXITCODE}
Function TProcess.GetExitCode : Integer;
begin
if Not Running then
Result:=GetExitStatus
else
Result:=0
end;
{$ENDIF}
Function TProcess.GetRunning : Boolean;
begin
IF FRunning then
FRunning:=Not PeekExitStatus;
Result:=FRunning;
end;
Procedure TProcess.CreateStreams(InHandle,OutHandle,ErrHandle : Longint);
begin
FreeStreams;
FInputStream:=TOutputPipeStream.Create (InHandle);
FOutputStream:=TInputPipeStream.Create (OutHandle);
if Not (poStderrToOutput in FProcessOptions) then
FStderrStream:=TInputPipeStream.Create(ErrHandle);
end;
procedure TProcess.FreeStream(var AStream: THandleStream);
begin
if AStream = nil then exit;
FreeAndNil(AStream);
end;
procedure TProcess.Loaded;
begin
inherited Loaded;
If (csDesigning in ComponentState) and (FCommandLine<>'') then
ConvertCommandLine;
end;
procedure TProcess.CloseInput;
begin
FreeStream(THandleStream(FInputStream));
end;
procedure TProcess.CloseOutput;
begin
FreeStream(THandleStream(FOutputStream));
end;
procedure TProcess.CloseStderr;
begin
FreeStream(THandleStream(FStderrStream));
end;
Procedure TProcess.SetWindowColumns (Value : Cardinal);
begin
if Value<>0 then
Include(FStartupOptions,suoUseCountChars);
dwXCountChars:=Value;
end;
Procedure TProcess.SetWindowHeight (Value : Cardinal);
begin
if Value<>0 then
include(FStartupOptions,suoUsePosition);
dwYSize:=Value;
end;
Procedure TProcess.SetWindowLeft (Value : Cardinal);
begin
if Value<>0 then
Include(FStartupOptions,suoUseSize);
dwx:=Value;
end;
Procedure TProcess.SetWindowTop (Value : Cardinal);
begin
if Value<>0 then
Include(FStartupOptions,suoUsePosition);
dwy:=Value;
end;
Procedure TProcess.SetWindowWidth (Value : Cardinal);
begin
If (Value<>0) then
Include(FStartupOptions,suoUseSize);
dwXSize:=Value;
end;
Function TProcess.GetWindowRect : TRect;
begin
With Result do
begin
Left:=dwx;
Right:=dwx+dwxSize;
Top:=dwy;
Bottom:=dwy+dwysize;
end;
end;
procedure TProcess.SetCommandLine(const AValue: String);
begin
if FCommandLine=AValue then exit;
FCommandLine:=AValue;
If Not (csLoading in ComponentState) then
ConvertCommandLine;
end;
procedure TProcess.SetParameters(const AValue: TStrings);
begin
FParameters.Assign(AValue);
end;
Procedure TProcess.SetWindowRect (Value : Trect);
begin
Include(FStartupOptions,suoUseSize);
Include(FStartupOptions,suoUsePosition);
With Value do
begin
dwx:=Left;
dwxSize:=Right-Left;
dwy:=Top;
dwySize:=Bottom-top;
end;
end;
Procedure TProcess.SetWindowRows (Value : Cardinal);
begin
if Value<>0 then
Include(FStartupOptions,suoUseCountChars);
dwYCountChars:=Value;
end;
procedure TProcess.SetApplicationName(const Value: String);
begin
FApplicationName := Value;
If (csDesigning in ComponentState) and
(FCommandLine='') then
FCommandLine:=Value;
end;
procedure TProcess.SetProcessOptions(const Value: TProcessOptions);
begin
FProcessOptions := Value;
If poNewConsole in FProcessOptions then
Exclude(FProcessOptions,poNoConsole);
if poRunSuspended in FProcessOptions then
Exclude(FProcessOptions,poWaitOnExit);
end;
procedure TProcess.SetActive(const Value: Boolean);
begin
if (Value<>GetRunning) then
If Value then
Execute
else
Terminate(0);
end;
procedure TProcess.SetEnvironment(const Value: TStrings);
begin
FEnvironment.Assign(Value);
end;
procedure TProcess.ConvertCommandLine;
begin
FParameters.Clear;
CommandToList(FCommandLine,FParameters);
If FParameters.Count>0 then
begin
Executable:=FParameters[0];
FParameters.Delete(0);
end;
end;
Const
READ_BYTES = 65536; // not too small to avoid fragmentation when reading large files.
// helperfunction that does the bulk of the work.
// We need to also collect stderr output in order to avoid
// lock out if the stderr pipe is full.
// L505: changed to ansistring
// function internalRuncommand(p:TProcess;out outputstring: string;
// out stderrstring: string; out exitstatus:integer):integer;
function internalRuncommand(p:TProcess;out outputstring: ansistring;
out stderrstring: ansistring; out exitstatus:integer):integer;
var
numbytes,bytesread,available : integer;
outputlength, stderrlength : integer;
stderrnumbytes,stderrbytesread : integer;
begin
result:=-1;
bytesread:=0;
outputlength:=0;
stderrbytesread:=0;
stderrlength:=0;
try
try
p.Options := p.Options + [poUsePipes];
p.Execute;
while p.Running do
begin
// Only call ReadFromStream if Data from corresponding stream
// is already available, otherwise, on linux, the read call
// is blocking, and thus it is not possible to be sure to handle
// big data amounts bboth on output and stderr pipes. PM.
available:=P.Output.NumBytesAvailable;
// writeln('DEBUG: bytesavail: ', P.Output.NumBytesAvailable);
if available > 0 then
begin
if (BytesRead + available > outputlength) then
begin
outputlength:=BytesRead + READ_BYTES;
Setlength(outputstring,outputlength);
end;
NumBytes := p.Output.Read(outputstring[1+bytesread], available);
// L505 if in the future above string is unicodestring, above may need work NOTE: pchar is zero based . http://docwiki.embarcadero.com/RADStudio/Seattle/en/Using_Streams_to_Read_or_Write_Data
// NumBytes := p.Output.Read(pchar(outputstring)[bytesread], available);
if NumBytes > 0 then
Inc(BytesRead, NumBytes);
end
// The check for assigned(P.stderr) is mainly here so that
// if we use poStderrToOutput in p.Options, we do not access invalid memory.
else if assigned(P.stderr) and (P.StdErr.NumBytesAvailable > 0) then
begin
available:=P.StdErr.NumBytesAvailable;
if (StderrBytesRead + available > stderrlength) then
begin
stderrlength:=StderrBytesRead + READ_BYTES;
Setlength(stderrstring,stderrlength);
end;
StderrNumBytes := p.StdErr.Read(stderrstring[1+StderrBytesRead], available);
// L505 in the future if the above is a unicodestring this may need work, and NOTE: pchar is zero based
// StderrNumBytes := p.StdErr.Read(pchar(stderrstring)[StderrBytesRead], available);
if StderrNumBytes > 0 then
Inc(StderrBytesRead, StderrNumBytes);
end
else
Sleep(100);
end;
// Get left output after end of execution
available:=P.Output.NumBytesAvailable;
while available > 0 do
begin
if (BytesRead + available > outputlength) then
begin
outputlength:=BytesRead + READ_BYTES;
Setlength(outputstring,outputlength);
end;
NumBytes := p.Output.Read(outputstring[1+bytesread], available);
// L505 if above is unicodestring in the future it may need work, and NOTE: pchar is zero based
// NumBytes := p.Output.Read(pchar(outputstring)[bytesread], available);
if NumBytes > 0 then
Inc(BytesRead, NumBytes);
available:=P.Output.NumBytesAvailable;
end;
setlength(outputstring,BytesRead);
while assigned(P.stderr) and (P.Stderr.NumBytesAvailable > 0) do
begin
available:=P.Stderr.NumBytesAvailable;
if (StderrBytesRead + available > stderrlength) then
begin
stderrlength:=StderrBytesRead + READ_BYTES;
Setlength(stderrstring,stderrlength);
end;
StderrNumBytes := p.StdErr.Read(stderrstring[1+StderrBytesRead], available);
// L505 if above is unicodestring in the future, it may need work and NOTE: pchar is zero based
// StderrNumBytes := p.StdErr.Read(pchar(stderrstring)[StderrBytesRead], available);
if StderrNumBytes > 0 then
Inc(StderrBytesRead, StderrNumBytes);
end;
setlength(stderrstring,StderrBytesRead);
exitstatus:=p.exitstatus;
result:=0; // we came to here, document that.
except
on e : Exception do
begin
result:=1;
setlength(outputstring,BytesRead);
end;
end;
finally
p.free;
end;
end;
{ Functions without StderrString }
Const
ForbiddenOptions = [poRunSuspended,poWaitOnExit];
// L505 changed to ansistring
// function RunCommandIndir(const curdir:string;const exename:string;const commands:array of string;out outputstring:string;out exitstatus:integer; Options : TProcessOptions = []):integer;
function RunCommandIndir(const curdir: string; const exename: string; const commands:array of string; out outputstring: ansistring;out exitstatus:integer; Options : TProcessOptions = []):integer;
Var
p : TProcess;
i : integer;
// ErrorString : String; // L505
ErrorString: ansistring;
begin
p:=TProcess.create(nil);
if Options<>[] then
P.Options:=Options - ForbiddenOptions;
p.Executable:=exename;
if curdir<>'' then
p.CurrentDirectory:=curdir;
if high(commands)>=0 then
for i:=low(commands) to high(commands) do
p.Parameters.add(commands[i]);
result:=internalruncommand(p,outputstring,errorstring,exitstatus);
end;
// L505 changed to ansistring
// function RunCommandInDir(const curdir,cmdline:string;out outputstring:string):boolean; deprecated;
function RunCommandInDir(const curdir,cmdline:string;out outputstring: ansistring):boolean; deprecated;
Var
p : TProcess;
exitstatus : integer;
// ErrorString : String; // L505
ErrorString: ansistring; // L505
begin
p:=TProcess.create(nil);
p.setcommandline(cmdline);
if curdir<>'' then
p.CurrentDirectory:=curdir;
result:=internalruncommand(p,outputstring,errorstring,exitstatus)=0;
if exitstatus<>0 then result:=false;
end;
// L505 changed to ansistring
// function RunCommandIndir(const curdir:string;const exename:string;const commands:array of string;out outputstring:string; Options : TProcessOptions = []):boolean;
function RunCommandIndir(const curdir: string; const exename: string; const commands:array of string; out outputstring: ansistring; Options : TProcessOptions = []):boolean;
Var
p : TProcess;
i,
exitstatus : integer;
// ErrorString : String; // L505
ErrorString: ansistring; // L505
begin
p:=TProcess.create(nil);
if Options<>[] then
P.Options:=Options - ForbiddenOptions;
p.Executable:=exename;
if curdir<>'' then
p.CurrentDirectory:=curdir;
if high(commands)>=0 then
for i:=low(commands) to high(commands) do
p.Parameters.add(commands[i]);
result:=internalruncommand(p,outputstring,errorstring,exitstatus)=0;
if exitstatus<>0 then result:=false;
end;
// L505 changed to ansistring
// function RunCommand(const cmdline:string; out outputstring:string):boolean; deprecated;
function RunCommand(const cmdline: string; out outputstring: ansistring):boolean; deprecated;
Var
p : TProcess;
exitstatus : integer;
// ErrorString : String; // L505
ErrorString: ansistring; // L505
begin
p:=TProcess.create(nil);
p.setcommandline(cmdline);
result:=internalruncommand(p,outputstring,errorstring,exitstatus)=0;
if exitstatus<>0 then result:=false;
end;
// L505: Changed to ansistring
// function RunCommand(const exename:string;const commands:array of string;out outputstring:string; Options : TProcessOptions = []):boolean;
function RunCommand(const exename:string; const commands:array of string; out outputstring: ansistring; Options : TProcessOptions = []):boolean;
Var
p : TProcess;
i,
exitstatus : integer;
// ErrorString : String; // L505
ErrorString: ansistring; // L505
begin
p:=TProcess.create(nil);
if Options<>[] then
P.Options:=Options - ForbiddenOptions;
p.Executable:=exename;
if high(commands)>=0 then
for i:=low(commands) to high(commands) do
p.Parameters.add(commands[i]);
result:=internalruncommand(p,outputstring,errorstring,exitstatus)=0;
if exitstatus<>0 then result:=false;
end;
end.