process.inc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. uses windows;
  2. Function TProcess.GetRunning : Boolean;
  3. begin
  4. IF FRunning then
  5. Frunning:=GetExitStatus=Still_Active;
  6. Result:=FRunning;
  7. end;
  8. Procedure TProcess.Execute;
  9. Var PName,PDir : PChar;
  10. FStartupInfo : TStartupInfo;
  11. FProcessAttributes,
  12. FTHreadAttributes : TSecurityAttributes;
  13. FProcessInformation : TProcessInformation;
  14. status : longbool;
  15. begin
  16. FillChar(FProcessAttributes,SizeOf(FProcessAttributes),#0);
  17. FillChar(FThreadAttributes,SizeOf(FThreadAttributes),#0);
  18. FillChar(FStartupInfo,SizeOf(FStartupInfo),#0);
  19. if poNoConsole in FCReateOptions then
  20. FCreationFlags:=FCreationFlags or Detached_Process;
  21. If poRunSuspended in FCreateOptions Then
  22. FCreationFlags:=FCreationFlags or Create_Suspended;
  23. If poUsePipes in FCreateOptions then
  24. begin
  25. FreeStreams;
  26. CreatePipeStreams (FChildInputSTream,FParentOutPutStream);
  27. CreatePipeStreams (FParentInputStream,FChildOutPutStream);
  28. if poStdErrToOutPut in FCreateOptions then
  29. CreatePipeStreams (FParentErrorStream,FChildErrorStream)
  30. else
  31. begin
  32. FChildErrorStream:=FChildOutPutStream;
  33. FParentErrorStream:=FParentInputStream;
  34. end;
  35. end;
  36. With FStartupInfo do
  37. begin
  38. if poUsePipes in FCreateOptions then
  39. begin
  40. dwFlags:=dwFlags or Startf_UseStdHandles;
  41. hStdInput:=FChildInputStream.Handle;
  42. hStdOutput:=FChildOutPutStream.Handle;
  43. hStdError:=FChildErrorStream.Handle;
  44. end;
  45. If (FFillAttribute<>-1) then
  46. begin
  47. dwFlags:=dwFlags or Startf_UseFillAttribute;
  48. dwFillAttribute:=FFIllAttribute;
  49. end;
  50. If FShowWindow then
  51. begin
  52. dwFlags:=dwFlags or Startf_UseShowWindow;
  53. // ?? dwXCountChars:=Value;
  54. end;
  55. if FWindowWidth<>-1 then
  56. begin
  57. dwFlags:=dwFlags or Startf_UseCountChars;
  58. dwXCountChars:=FWindowWidth;
  59. end;
  60. if FWindowRows<>-1 then
  61. begin
  62. dwFlags:=dwFlags or Startf_UseCountChars;
  63. dwYCountChars:=FWindowRows;
  64. end;
  65. if FWindowHeight<>-1 then
  66. begin
  67. dwFlags:=dwFlags or Startf_UsePosition;
  68. dwYsize:=FWindowHeight;
  69. end;
  70. If FWindowWidth<>-1 then
  71. begin
  72. dwFlags:=dwFlags or Startf_UsePosition;
  73. dwxsize:=FWindowWidth;
  74. end;
  75. IF FWindowLeft<>-1 then
  76. begin
  77. dwFlags:=dwFlags or Startf_UseSize;
  78. dwx:=FWindowLeft;
  79. end;
  80. If FWindowTop<>-1 then
  81. begin
  82. dwFlags:=dwFlags or Startf_UseSize;
  83. dwy:=FWindowTop;
  84. end;
  85. end;
  86. Writeln ('About to start');
  87. If FApplicationName<>'' then PName:=Pchar(FApplicationName) else PName:=Nil;
  88. If FCurrentDirectory<>'' then PName:=Pchar(FCurrentDirectory) else PDir:=Nil;
  89. Status:=CreateProcess (Pname,PChar(FCommandLine),@FProcessAttributes,@FThreadAttributes,
  90. FInheritHandles,FCreationFlags,FEnvironment,PDir,@FStartupInfo,
  91. @fProcessInformation);
  92. Writeln ('Created ',Status);
  93. FTHreadHandle:=fProcessInformation.hthread;
  94. Writeln ('ThreadHandle :',FThreadHandle);
  95. FHandle:=fProcessInformation.hProcess;
  96. Writeln ('Process Handle :',FHandle);
  97. FPID:=fProcessInformation.dwProcessID;
  98. Writeln ('Process Handle :',FPID);
  99. FRunning:=True;
  100. if (poWaitOnExit in FCreateOptions) and
  101. not (poRunSuspended in FCreateOptions) then
  102. WaitOnExit;
  103. end;
  104. Function TProcess.WaitOnExit : Dword;
  105. begin
  106. Result:=WaitForSingleObject (FHandle,Infinite);
  107. If Result<>Wait_Failed then
  108. GetExitStatus;
  109. FRunning:=False;
  110. end;
  111. Function TProcess.Suspend : Longint;
  112. begin
  113. Result:=SuspendThread(ThreadHandle);
  114. end;
  115. Function TProcess.Resume : LongInt;
  116. begin
  117. Result:=ResumeThread(ThreadHandle);
  118. end;
  119. Function TProcess.Terminate(AExitCode : Integer) : Boolean;
  120. begin
  121. Result:=False;
  122. If ExitStatus=Still_active then
  123. Result:=TerminateProcess(Handle,AexitCode);
  124. end;
  125. {
  126. $Log$
  127. Revision 1.3 2000-07-25 11:27:35 jonas
  128. * fixed missing comment openers for log section
  129. Revision 1.2 2000/07/13 11:33:07 michael
  130. + removed logs
  131. }