13
13
**********************************************************************}
28
TProcessOptions = (poExecuteOnCreate,poRunSuspended,poUsePipes,
29
poNoConsole,poStderrToOutPut,poWaitOnExit);
31
TCreateOptions = Set of TPRocessOptions;
33
TProcess = Class (TObject)
35
FShowWindow : Boolean;
42
FWindowWidth : Longint;
44
FApplicationName : string;
45
FChildErrorStream : TOutPutPipeStream;
46
FChildInputSTream : TInputPipeStream;
47
FChildOutPutStream : TOutPutPipeStream;
48
FConsoleTitle : String;
49
FCreateOptions : TCreateOptions;
50
FCreationFlags : Cardinal;
51
FCommandLine : String;
52
FCurrentDirectory : String;
54
FEnvironment : Pointer;
59
FInherithandles : LongBool;
60
FParentErrorStream : TInputPipeStream;
61
FParentInputSTream : TInputPipeStream;
62
FParentOutputStream : TOutPutPipeStream;
65
Procedure FreeStreams;
66
Function GetExitStatus : Integer;
67
Function GetRunning : Boolean;
68
Function GetWindowRect : TRect;
69
Procedure SetWindowRect (Value : TRect);
71
Constructor Create (Const ACommandline : String;
72
Options : TCreateOptions);
73
Destructor Destroy; override;
74
Procedure Execute; virtual;
75
Function Resume : Integer; virtual;
76
Function Suspend : Integer; virtual;
77
Function Terminate (AExitCode : Integer): Boolean; virtual;
78
Function WaitOnExit : DWord;
80
Property ApplicationName : String Read FApplicationname
81
Write FApplicationname;
82
Property CommandLine : String Read FCommandLine;
83
Property ConsoleTitle : String Read FConsoleTitle Write FConsoleTitle;
84
Property CurrentDirectory : String Read FCurrentDirectory
85
Write FCurrentDirectory;
86
Property CreateOptions : TCreateOptions Read FCreateOptions;
87
Property CreationFlags : Cardinal Read FCreationFlags Write FCreationFlags;
88
Property DeskTop : String Read FDeskTop Write FDeskTop;
89
Property Environment : Pointer Read FEnvironment Write FEnvironment;
90
Property ExitStatus : Integer Read GetExitStatus;
91
Property FillAttribute : Longint Read FFillAttribute Write FFillAttribute;
92
Property Handle : THandle Read FHandle;
93
Property ThreadHandle : THandle Read FThreadHandle;
94
Property PID : Longint;
95
Property Input : TOutPutPipeStream Read FParentOutPutStream;
96
Property InheritHandles : LongBool Read FInheritHandles;
97
Property OutPut : TInputPipeStream Read FParentInputStream;
98
Property Running : Boolean Read GetRunning;
99
Property ShowWindow : Boolean Read FShowWindow Write FShowWindow;
100
Property StdErr : TinputPipeStream Read FParentErrorStream;
101
Property WindowColumns : Longint Read FWindowColumns Write FWindowColumns;
102
Property WindowHeight : Longint Read FWindowHeight Write FWindowHeight;
103
Property WindowLeft : Longint Read FWindowLeft Write FWindowLeft;
104
Property WindowRows : Longint Read FWindowRows Write FWindowRows;
105
Property WindowTop : Longint Read FWindowTop Write FWindowTop;
106
Property WindowWidth : Longint Read FWindowWidth Write FWindowWidth;
107
Property WindowRect : Trect Read GetWindowRect Write SetWindowRect;
35
TProcessOption = (poRunSuspended,poWaitOnExit,
36
poUsePipes,poStderrToOutPut,
37
poNoConsole,poNewConsole,
38
poDefaultErrorMode,poNewProcessGroup,
39
poDebugProcess,poDebugOnlyThisProcess);
41
TShowWindowOptions = (swoNone,swoHIDE,swoMaximize,swoMinimize,swoRestore,swoShow,
42
swoShowDefault,swoShowMaximized,swoShowMinimized,
43
swoshowMinNOActive,swoShowNA,swoShowNoActivate,swoShowNormal);
45
TStartupOption = (suoUseShowWindow,suoUseSize,suoUsePosition,
46
suoUseCountChars,suoUseFillAttribute);
48
TProcessPriority = (ppHigh,ppIdle,ppNormal,ppRealTime);
50
TProcessOptions = Set of TPRocessOption;
51
TstartUpoptions = set of TStartupOption;
55
STARTF_USESHOWWINDOW = 1; // Ignored
57
STARTF_USEPOSITION = 4;
58
STARTF_USECOUNTCHARS = 8; // Ignored
59
STARTF_USEFILLATTRIBUTE = $10;
60
STARTF_RUNFULLSCREEN = $20; // Ignored
61
STARTF_FORCEONFEEDBACK = $40; // Ignored
62
STARTF_FORCEOFFFEEDBACK = $80; // Ignored
63
STARTF_USESTDHANDLES = $100; // Ignored
64
STARTF_USEHOTKEY = $200; // Ignored
67
PProcessInformation = ^TProcessInformation;
68
TProcessInformation = record
75
PStartupInfo = ^TStartupInfo;
87
dwFillAttribute: DWORD;
97
PSecurityAttributes = ^TSecurityAttributes;
98
TSecurityAttributes = Record
100
lpSecurityDescriptor : Pointer;
101
BinheritHandle : Boolean;
104
Const piInheritablePipe : TSecurityAttributes = (
105
nlength:SizeOF(TSecurityAttributes);
106
lpSecurityDescriptor:Nil;
107
Binherithandle:True);
108
piNonInheritablePipe : TSecurityAttributes = (
109
nlength:SizeOF(TSecurityAttributes);
110
lpSecurityDescriptor:Nil;
111
Binherithandle:False);
116
TProcess = Class (TComponent)
121
FApplicationName : string;
122
FChildErrorStream : TOutPutPipeStream;
123
FChildInputSTream : TInputPipeStream;
124
FChildOutPutStream : TOutPutPipeStream;
125
FConsoleTitle : String;
126
FProcessOptions : TProcessOptions;
127
FStartUpOptions : TStartupOptions;
128
FCommandLine : String;
129
FCurrentDirectory : String;
131
FEnvironment : Tstrings;
132
FExitCode : Cardinal;
134
FShowWindow : TShowWindowOptions;
135
FInherithandles : LongBool;
136
FParentErrorStream : TInputPipeStream;
137
FParentInputSTream : TInputPipeStream;
138
FParentOutputStream : TOutPutPipeStream;
140
FThreadAttributes : PSecurityAttributes;
141
FProcessAttributes : PSecurityAttributes;
142
FProcessInformation : TProcessInformation;
143
FPRocessPriority : TProcessPriority;
144
FStartupInfo : TStartupInfo;
145
Procedure FreeStreams;
146
Function GetExitStatus : Integer;
147
Function GetHandle : THandle;
148
Function GetRunning : Boolean;
149
Function GetProcessAttributes : TSecurityAttributes;
150
Function GetThreadAttributes : TSecurityAttributes;
151
Procedure SetProcessAttributes (Value : TSecurityAttributes);
152
Procedure SetThreadAttributes (Value : TSecurityAttributes);
153
Function GetWindowRect : TRect;
154
Procedure SetWindowRect (Value : TRect);
155
Procedure SetFillAttribute (Value : Cardinal);
156
Procedure SetShowWindow (Value : TShowWindowOptions);
157
Procedure SetWindowColumns (Value : Cardinal);
158
Procedure SetWindowHeight (Value : Cardinal);
159
Procedure SetWindowLeft (Value : Cardinal);
160
Procedure SetWindowRows (Value : Cardinal);
161
Procedure SetWindowTop (Value : Cardinal);
162
Procedure SetWindowWidth (Value : Cardinal);
163
procedure CreateStreams;
164
function GetCreationFlags: Cardinal;
165
function GetStartupFlags: Cardinal;
166
procedure SetApplicationname(const Value: String);
167
procedure SetPRocessOptions(const Value: TProcessOptions);
168
procedure SetActive(const Value: Boolean);
169
procedure SetEnvironment(const Value: TStrings);
171
function PeekLinuxExitStatus: Boolean;
174
Constructor Create (AOwner : TComponent);override;
175
Destructor Destroy; override;
176
Procedure Execute; virtual;
177
Function Resume : Integer; virtual;
178
Function Suspend : Integer; virtual;
179
Function Terminate (AExitCode : Integer): Boolean; virtual;
180
Function WaitOnExit : DWord;
181
Property WindowRect : Trect Read GetWindowRect Write SetWindowRect;
182
Property StartupInfo : TStartupInfo Read FStartupInfo;
183
Property ProcessAttributes : TSecurityAttributes Read GetProcessAttributes Write SetProcessAttributes;
184
Property ProcessInformation : TProcessInformation Read FPRocessInformation;
185
Property Handle : THandle Read FProcessInformation.hProcess;
186
Property ThreadHandle : THandle Read FprocessInformation.hThread;
187
Property Input : TOutPutPipeStream Read FParentOutPutStream;
188
Property OutPut : TInputPipeStream Read FParentInputStream;
189
Property StdErr : TinputPipeStream Read FParentErrorStream;
190
Property ExitStatus : Integer Read GetExitStatus;
191
Property InheritHandles : LongBool Read FInheritHandles Write FInheritHandles;
192
Property ThreadAttributes : TSecurityAttributes Read GetThreadAttributes Write SetThreadAttributes;
194
Property Active : Boolean Read Getrunning Write SetActive;
195
Property ApplicationName : String Read FApplicationname Write SetApplicationname;
196
Property CommandLine : String Read FCommandLine Write FCommandLine;
197
Property ConsoleTitle : String Read FConsoleTitle Write FConsoleTitle;
198
Property CurrentDirectory : String Read FCurrentDirectory Write FCurrentDirectory;
199
Property DeskTop : String Read FDeskTop Write FDeskTop;
200
Property Environment : TStrings Read FEnvironment Write SetEnvironment;
201
Property FillAttribute : Cardinal Read FStartupInfo.dwFillAttribute Write SetFillAttribute;
202
Property Options : TProcessOptions Read FProcessOptions Write SetPRocessOptions;
203
Property Priority : TProcessPriority Read FProcessPriority Write FProcessPriority;
204
Property StartUpOptions : TStartUpOptions Read FStartUpOptions Write FStartupOptions;
205
Property Running : Boolean Read GetRunning;
206
Property ShowWindow : TShowWindowOptions Read FShowWindow Write SetShowWindow;
207
Property WindowColumns : Cardinal Read FStartupInfo.dwXCountchars Write SetWindowColumns;
208
Property WindowHeight : Cardinal Read FStartupInfo.dwYsize Write SetWindowHeight;
209
Property WindowLeft : Cardinal Read FStartupInfo.dwx Write SetWindowLeft;
210
Property WindowRows : Cardinal Read FStartupInfo.dwYcountChars Write SetWindowRows;
211
Property WindowTop : Cardinal Read FStartupInfo.dwy Write SetWindowTop ;
212
Property WindowWidth : Cardinal Read FStartupInfo.dwXsize Write SetWindowWidth;
217
PriorityConstants : Array [TProcessPriority] of Integer =
221
GeometryOption : String = '-geometry';
222
TitleOption : String ='-title';
226
PriorityConstants : Array [TProcessPriority] of Cardinal =
227
(HIGH_PRIORITY_CLASS,IDLE_PRIORITY_CLASS,
228
NORMAL_PRIORITY_CLASS,REALTIME_PRIORITY_CLASS);
114
Constructor TProcess.Create (Const ACommandline : String;
115
Options : TCreateOptions);
232
Constructor TProcess.Create (AOwner : TComponent);
118
FCreateOptions:=Options;
119
FCommandLine:=ACommandLine;
236
FAccess:=PROCESS_ALL_ACCESS;
238
FProcessPriority:=ppNormal;
239
FShowWindow:=swoNone;
240
FStartupInfo.cb:=SizeOf(TStartupInfo);
120
241
FInheritHandles:=True;
121
FFillAttribute := -1;
122
FWindowColumns := -1;
128
If poExecuteOnCreate in FCreateOptions then
242
FEnvironment:=TStringList.Create;
132
245
Destructor TProcess.Destroy;
248
If assigned (FProcessAttributes) then Dispose (FPRocessAttributes);
249
If assigned (FThreadAttributes) then Dispose (FThreadAttributes);
138
255
Procedure TProcess.FreeStreams;
257
var FreedStreams: TList;
259
procedure FreeStream(var AnObject: THandleStream);
262
if (AnObject<>Nil) and (FreedStreams.IndexOf(AnObject)<0) then
264
FileClose(AnObject.Handle);
265
FreedStreams.Add(AnObject);
141
if FChildErrorStream<>FChildoutputStream then
143
FChildErrorStream.free;
144
FParentErrorStream.free;
146
FParentInputSTream.Free;
147
FParentOutputStream.Free;
148
FChildInputSTream.Free;
149
FChildOutPutStream.Free;
272
FreedStreams:=TList.Create;
274
FreeStream(FParentErrorStream);
275
FreeStream(FParentInputStream);
276
FreeStream(FParentOutputStream);
277
FreeStream(FChildErrorStream);
278
FreeStream(FChildInputStream);
279
FreeStream(FChildOutputStream);
152
285
Function TProcess.GetExitStatus : Integer;
157
GetExitCodeProcess(Handle,@FExitCode);
292
GetExitCodeProcess(Handle,FExitCode);
159
294
Result:=FExitCode;
297
Function TProcess.GetHandle : THandle;
302
FHandle:=OpenProcess (FAccess,True,FProcessInformation.dwProcessId);
307
Function TProcess.GetProcessAttributes : TSecurityAttributes;
309
Var P : PSecurityAttributes;
312
IF not Assigned(FProcessAttributes) then
314
// Provide empty dummy value;
316
Fillchar(p^,Sizeof(TSecurityAttributes),0);
320
REsult:=FProcessAttributes^;
324
Function TProcess.PeekLinuxExitStatus : Boolean;
327
Result:={$ifdef VER1_0}WaitPID{$else}fpWaitPid{$endif}(Handle,@FExitCode,WNOHANG)=Handle;
329
FExitCode:=wexitstatus(FExitCode)
335
Function TProcess.GetRunning : Boolean;
341
FRunning:=Not PeekLinuxExitStatus;
343
Frunning:=GetExitStatus=Still_Active;
349
Function TProcess.GetThreadAttributes : TSecurityAttributes;
351
Var P : PSecurityAttributes;
354
IF not Assigned(FThreadAttributes) then
356
// Provide empty dummy value;
358
Fillchar(p^,Sizeof(TSecurityAttributes),0);
362
Result:=FThreadAttributes^;
365
Procedure TProcess.SetProcessAttributes (Value : TSecurityAttributes);
368
If not Assigned (FProcessAttributes) then
369
New(FProcessAttributes);
370
FPRocessAttributes^:=VAlue;
373
Procedure TProcess.SetThreadAttributes (Value : TSecurityAttributes);
376
If not Assigned (FThreadAttributes) then
377
New(FThreadAttributes);
378
FThreadAttributes^:=VAlue;
381
Procedure TProcess.CreateStreams;
385
CreatePipeStreams (FChildInputSTream,FParentOutPutStream); //,@piInheritablePipe,1024);
386
CreatePipeStreams (FParentInputStream,FChildOutPutStream); //,@piInheritablePipe,1024);
387
if Not (poStdErrToOutPut in FProcessOptions) then
388
CreatePipeStreams (FParentErrorStream,FChildErrorStream) //,@piInheritablePipe,1024)
391
FChildErrorStream:=FChildOutPutStream;
392
FParentErrorStream:=FParentInputStream;
394
FStartupInfo.dwFlags:=FStartupInfo.dwFlags or Startf_UseStdHandles;
395
FStartupInfo.hStdInput:=FChildInputStream.Handle;
396
FStartupInfo.hStdOutput:=FChildOutPutStream.Handle;
397
FStartupInfo.hStdError:=FChildErrorStream.Handle;
400
Function TProcess.GetCreationFlags : Cardinal;
405
if poNoConsole in FProcessOptions then
406
Result:=Result or Detached_Process;
407
if poNewConsole in FProcessOptions then
408
Result:=Result or Create_new_console;
409
if poNewProcessGroup in FProcessOptions then
410
Result:=Result or CREATE_NEW_PROCESS_GROUP;
411
If poRunSuspended in FProcessOptions Then
412
Result:=Result or Create_Suspended;
413
if poDebugProcess in FProcessOptions Then
414
Result:=Result or DEBUG_PROCESS;
415
if poDebugOnlyThisProcess in FProcessOptions Then
416
Result:=Result or DEBUG_ONLY_THIS_PROCESS;
417
if poDefaultErrorMode in FProcessOptions Then
418
Result:=Result or CREATE_DEFAULT_ERROR_MODE;
419
result:=result or PriorityConstants[FProcessPriority];
423
Function TProcess.GetStartupFlags : Cardinal;
427
if poUsePipes in FProcessOptions then
428
Result:=Result or Startf_UseStdHandles;
429
if suoUseShowWindow in FStartupOptions then
430
Result:=Result or startf_USESHOWWINDOW;
431
if suoUSESIZE in FStartupOptions then
432
Result:=Result or startf_usesize;
433
if suoUsePosition in FStartupOptions then
434
Result:=Result or startf_USEPOSITION;
435
if suoUSECOUNTCHARS in FStartupoptions then
436
Result:=Result or startf_usecountchars;
437
if suoUsefIllAttribute in FStartupOptions then
438
Result:=Result or startf_USEFILLATTRIBUTE;
443
TPCharArray = Array[Word] of pchar;
444
PPCharArray = ^TPcharArray;
447
Function StringsToPCharList(List : TStrings) : PPChar;
455
GetMem(Result,I*sizeOf(PChar));
456
PPCharArray(Result)^[List.Count]:=Nil;
457
For I:=0 to List.Count-1 do
460
Result[i]:=StrNew(PChar(S));
464
Procedure FreePCharList(List : PPChar);
471
While List[i]<>Nil do
481
Function StringsToPChars(List : TStrings): pointer;
489
For I:=0 to List.Count-1 do
490
EnvBlock := EnvBlock + List[i] + #0;
491
EnvBlock := EnvBlock + #0;
492
GetMem(Result, Length(EnvBlock));
493
CopyMemory(Result, @EnvBlock[1], Length(EnvBlock));
499
Procedure CommandToList(S : String; List : TStrings);
501
Function GetNextWord : String;
504
WhiteSpace = [' ',#8,#10];
505
Literals = ['"',''''];
508
Wstart,wend : Integer;
514
While (WStart<=Length(S)) and (S[WStart] in WhiteSpace) do
519
While (Wend<=Length(S)) and (Not (S[Wend] in WhiteSpace) or InLiteral) do
521
if S[Wend] in Literals then
523
InLiteral:=Not (S[Wend]=LastLiteral)
527
LastLiteral:=S[Wend];
531
Result:=Copy(S,WStart,WEnd-WStart);
532
Result:=StringReplace(Result,'"','',[rfReplaceAll]);
533
Result:=StringReplace(Result,'''','',[rfReplaceAll]);
534
While (WEnd<=Length(S)) and (S[Wend] in WhiteSpace) do
553
Function MakeCommand(Var AppName,CommandLine : String;
554
StartupOptions : TStartUpOptions;
555
ProcessOptions : TProcessOptions;
556
StartupInfo : TStartupInfo) : PPchar;
558
SNoCommandLine = 'Cannot execute empty command-line';
567
If (CommandLine='') then
568
Raise Exception.Create(SNoCommandline)
572
If (CommandLine='') then
573
CommandLine:=AppName;
575
S:=TStringList.Create;
577
CommandToList(CommandLine,S);
578
if poNewConsole in ProcessOptions then
581
If (AppName<>'') then
584
S.Insert(0,'-title');
586
if suoUseCountChars in StartupOptions then
589
S.Insert(0,Format('%dx%d',[dwXCountChars,dwYCountChars]));
590
S.Insert(0,'-geometry');
594
if (AppName<>'') then
602
if (suoUseSize in StartupOptions) then
603
g:=format('%dx%d',[dwXSize,dwYsize]);
604
if (suoUsePosition in StartupOptions) then
605
g:=g+Format('+%d+%d',[dwX,dwY]);
608
S.Add(GeometryOption);
612
Result:=StringsToPcharList(S);
619
Function CreateProcess (PName,PCommandLine,PDir : String;
621
StartupOptions : TStartupOptions;
622
ProcessOptions : TProcessOptions;
623
const FStartupInfo : TStartupInfo;
624
Var ProcessInfo : TProcessInformation) : boolean;
633
Argv:=MakeCommand(Pname,PCommandLine,StartupOptions,ProcessOptions,FStartupInfo);
634
if (pos('/',PName)<>1) then
635
PName:=FileSearch(Pname,{$ifdef ver1_0}GetEnv{$else}fpgetenv{$endif}('PATH'));
636
Pid:={$ifdef ver1_0}fork;{$else}fpfork;{$endif}
639
{ We're in the child }
642
if PoUsePipes in ProcessOptions then
644
{$ifdef ver1_0}dup2{$else}fpdup2{$endif}(FStartupInfo.hStdInput,0);
645
{$ifdef ver1_0}dup2{$else}fpdup2{$endif}(FStartupInfo.hStdOutput,1);
646
{$ifdef ver1_0}dup2{$else}fpdup2{$endif}(FStartupInfo.hStdError,2);
648
else if poNoConsole in ProcessOptions then
650
fd:=FileOpen('/dev/null',fmOpenReadWrite);
651
{$ifdef ver1_0}dup2{$else}fpdup2{$endif}(fd,0);
652
{$ifdef ver1_0}dup2{$else}fpdup2{$endif}(fd,1);
653
{$ifdef ver1_0}dup2{$else}fpdup2{$endif}(fd,2);
655
if (poRunSuspended in ProcessOptions) then
658
{$ifdef ver1_0}execve{$else}fpexecve{$endif}(PChar(PName),Argv,Fenv)
660
{$ifdef ver1_0}execv{$else}fpexecv{$endif}(Pchar(PName),argv);
666
// Copy process information.
667
ProcessInfo.hProcess:=PID;
668
ProcessInfo.hThread:=PID;
669
ProcessInfo.dwProcessId:=PID;
670
ProcessInfo.dwThreadId:=PID;
676
Function GetLastError : Integer;
683
Procedure TProcess.Execute;
688
PName,PDir,PCommandLine : PChar;
693
FCreationFlags : Cardinal;
696
If poUsePipes in FProcessOptions then
698
FCreationFlags:=GetCreationFlags;
699
FStartupInfo.dwFlags:=GetStartupFlags;
704
If FApplicationName<>'' then
705
PName:=Pchar(FApplicationName);
706
If FCommandLine<>'' then
707
PCommandLine:=Pchar(FCommandLine);
708
If FCurrentDirectory<>'' then
709
PDir:=Pchar(FCurrentDirectory);
711
if FEnvironment.Count<>0 then
713
FEnv:=StringsToPcharList(FEnvironment)
715
FEnv:=StringsToPChars(FEnvironment)
719
FInheritHandles:=True;
721
if Not CreateProcess (FApplicationName,FCommandLine,FCurrentDirectory,FEnv,
722
FStartupOptions,FProcessOptions,FStartupInfo,
723
fProcessInformation) then
725
If Not CreateProcess (PName,PCommandLine,FProcessAttributes,FThreadAttributes,
726
FInheritHandles,FCreationFlags,FEnv,PDir,FStartupInfo,
727
fProcessInformation) then
729
Raise Exception.CreateFmt('Failed to execute %s : %d',[FCommandLine,GetLastError]);
730
if POUsePipes in FProcessOptions then
732
FileClose(FStartupInfo.hStdInput);
733
FileClose(FStartupInfo.hStdOutput);
734
if Not (poStdErrToOutPut in FProcessOptions) then
735
FileClose(FStartupInfo.hStdError);
738
Fhandle:=fprocessinformation.hProcess;
747
if not (csDesigning in ComponentState) and // This would hang the IDE !
748
(poWaitOnExit in FProcessOptions) and
749
not (poRunSuspended in FProcessOptions) then
753
Function TProcess.WaitOnExit : Dword;
757
Result:=Dword({$ifdef ver1_0}WaitPid{$else}fpWaitPid{$endif}(Handle,@FExitCode,0));
758
If Result=Handle then
759
FExitCode:=WexitStatus(FExitCode);
761
Result:=WaitForSingleObject (FprocessInformation.hProcess,Infinite);
762
If Result<>Wait_Failed then
768
Function TProcess.Suspend : Longint;
772
If {$ifdef ver1_0}kill{$else}fpkill{$endif}(Handle,SIGSTOP)<>0 then
777
Result:=SuspendThread(ThreadHandle);
781
Function TProcess.Resume : LongInt;
785
If {$ifdef ver1_0}kill{$else}fpkill{$endif}(Handle,SIGCONT)<>0 then
790
Result:=ResumeThread(ThreadHandle);
794
Function TProcess.Terminate(AExitCode : Integer) : Boolean;
799
Result:={$ifdef ver1_0}kill{$else}fpkill{$endif}(Handle,SIGTERM)=0;
803
Result:={$ifdef ver1_0}kill{$else}fpkill{$endif}(Handle,SIGKILL)=0;
807
If ExitStatus=Still_active then
808
Result:=TerminateProcess(Handle,AexitCode);
812
Procedure TProcess.SetFillAttribute (Value : Cardinal);
815
FStartupInfo.dwFlags:=FStartupInfo.dwFlags or Startf_UseFillAttribute;
816
FStartupInfo.dwFillAttribute:=Value;
819
Procedure TProcess.SetShowWindow (Value : TShowWindowOptions);
823
SWC : Array [TShowWindowOptions] of Cardinal =
824
(0,SW_HIDE,SW_Maximize,SW_Minimize,SW_Restore,SW_Show,
825
SW_ShowDefault,SW_ShowMaximized,SW_ShowMinimized,
826
SW_showMinNOActive,SW_ShowNA,SW_ShowNoActivate,SW_ShowNormal);
831
if Value<>swoNone then
832
FStartupInfo.dwFlags:=FStartupInfo.dwFlags or Startf_UseShowWindow
834
FStartupInfo.dwFlags:=FStartupInfo.dwFlags and not Startf_UseShowWindow;
836
FStartupInfo.wShowWindow:=SWC[Value];
840
Procedure TProcess.SetWindowColumns (Value : Cardinal);
844
Include(FStartUpOptions,suoUseCountChars);
845
FStartupInfo.dwXCountChars:=Value;
849
Procedure TProcess.SetWindowHeight (Value : Cardinal);
853
include(FStartUpOptions,suoUsePosition);
854
FStartupInfo.dwYsize:=Value;
857
Procedure TProcess.SetWindowLeft (Value : Cardinal);
861
Include(FStartUpOptions,suoUseSize);
862
FStartupInfo.dwx:=Value;
865
Procedure TProcess.SetWindowTop (Value : Cardinal);
869
Include(FStartUpOptions,suoUsePosition);
870
FStartupInfo.dwy:=Value;
873
Procedure TProcess.SetWindowWidth (Value : Cardinal);
876
Include(FStartUpOptions,suoUseSize);
877
FStartupInfo.dwxsize:=Value;
162
880
Function TProcess.GetWindowRect : TRect;
168
Right:=FWindowLeft+FWindowWidth;
169
Bottom:=FWindowTop+FWindowRows;
173
Procedure TProcess.SetWindowRect (Value : classes.Trect);
892
Procedure TProcess.SetWindowRect (Value : Trect);
894
Include(FStartupOptions,suouseSize);
895
Include(FStartupOptions,suoUsePosition);
178
FWindowWidth:=Right-Left;
180
FWindowRows:=Bottom-top;
907
Procedure TProcess.SetWindowRows (Value : Cardinal);
910
FStartupInfo.dwFlags:=FStartupInfo.dwFlags or Startf_UseCountChars;
911
FStartupInfo.dwYCountChars:=Value;
914
procedure TProcess.SetApplicationname(const Value: String);
916
FApplicationname := Value;
917
If (csdesigning in ComponentState) and
918
(FCommandLine='') then
922
procedure TProcess.SetProcessOptions(const Value: TProcessOptions);
924
FProcessOptions := Value;
925
If poNewConsole in FPRocessOptions then
926
Exclude(FProcessoptions,poNoConsole);
927
if poRunSuspended in FProcessOptions then
928
Exclude(FPRocessoptions,poWaitOnExit);
931
procedure TProcess.SetActive(const Value: Boolean);
933
if (Value<>GetRunning) then
940
procedure TProcess.SetEnvironment(const Value: TStrings);
942
FEnvironment.Assign(Value);
187
947
$Log: process.pp,v $
188
Revision 1.1 2000/07/13 06:31:31 michael
191
Revision 1.7 2000/03/28 06:44:01 michael
192
+ TRect should refer to the classes one
194
Revision 1.6 2000/02/15 22:03:38 sg
195
* Inserted wrong copyright notice ;) Fixed.
197
Revision 1.5 2000/02/15 21:57:51 sg
198
* Added copyright notice and CVS log tags where necessary
948
Revision 1.19 2004/02/03 08:12:22 michael
949
+ Patch from Vincent Snijders to fix passing environment vars in win32
951
Revision 1.18 2003/10/30 20:34:47 florian
952
* fixed inherited destroy; call of tprocess
954
Revision 1.17 2003/09/20 12:38:29 marco
955
* FCL now compiles for FreeBSD with new 1.1. Now Linux.
957
Revision 1.16 2003/08/12 13:49:42 michael
958
+ Freed streams were not closed correctly
960
Revision 1.15 2003/05/08 20:04:16 armin
961
* Dont close FStartupInfo.hStdError if options include poStdErrToOutPut
963
Revision 1.14 2003/04/27 21:21:42 sg
964
* Added typecast to prevent range check error in TProcess.WaitOnExit
966
Revision 1.13 2002/09/07 15:15:25 peter
967
* old logs removed and tabs fixed