Declaration¶
Source position: processbody.inc line 117
type
TProcess = class(TComponent)
public
constructor Create;
destructor Destroy;
procedure Execute;
procedure CloseInput;
procedure CloseOutput;
procedure CloseStderr;
function Resume : Integer;
function Suspend : Integer;
function Terminate : Boolean;
function WaitOnExit : Boolean;
function WaitOnExit(Timeout: DWord) : Boolean;
function ReadInputStream(p: TInputPipeStream; var BytesRead: Integer;
var DataLength: Integer; var Data: string;
MaxLoops: Integer=10) : Boolean;
function ReadInputStream(p: TInputPipeStream; data: TStream;
MaxLoops: Integer=10) : Boolean;
function RunCommandLoop : Integer;
property WindowRect: Trect; {rw}
property Handle: THandle; {r}
property ProcessHandle: THandle; {r}
property ThreadHandle: THandle; {r}
property ProcessID: Integer; {r}
property ThreadID: Integer; {r}
property Input: TOutputPipeStream; {r}
property Output: TInputPipeStream; {r}
property Stderr: TInputPipeStream; {r}
property ExitStatus: Integer; {r}
property ExitCode: Integer; {r}
property InheritHandles: Boolean; {rw}
property OnRunCommandEvent: TOnRunCommandEvent; {rw}
property RunCommandSleepTime: Integer; {rw}
property OnForkEvent: TProcessForkEvent; {rw}
published
property PipeBufferSize: Cardinal; {rwd}
property Active: Boolean; {rw}
property ApplicationName: TProcessString; {rw}
property CommandLine: TProcessString; {rw}
property Executable: TProcessString; {rw}
property Parameters: TProcessStrings; {rw}
property ConsoleTitle: TProcessString; {rw}
property CurrentDirectory: TProcessString; {rw}
property Desktop: string; {rw}
property Environment: TProcessStrings; {rw}
property Options: TProcessOptions; {rw}
property Priority: TProcessPriority; {rw}
property StartupOptions: TStartupOptions; {rw}
property Running: Boolean; {r}
property ShowWindow: TShowWindowOptions; {rw}
property SkipCommandLineQuotes: Boolean; {rw}
property WindowColumns: Cardinal; {rw}
property WindowHeight: Cardinal; {rw}
property WindowLeft: Cardinal; {rw}
property WindowRows: Cardinal; {rw}
property WindowTop: Cardinal; {rw}
property WindowWidth: Cardinal; {rw}
property FillAttribute: Cardinal; {rw}
property XTermProgram: string; {rw}
property InputDescriptor: TIODescriptor; {rw}
property OutputDescriptor: TIODescriptor; {rw}
property ErrorDescriptor: TIODescriptor; {rw}
end;
Inheritance¶
Description¶
TProcess is a component that can be used to start and control other processes (programs/binaries). It contains a lot of options that control how the process is started. Many of these are Win32 specific, and have no effect on other platforms, so they should be used with care.
The simplest way to use this component is to create an instance, set the CommandLine property to the full pathname of the program that should be executed, and call Execute. To determine whether the process is still running (i.e. has not stopped executing), the Running property can be checked.
More advanced techniques can be used with the Options settings.
Properties¶
| Member | Visibility | Description |
|---|---|---|
| Active | published | Start or stop the process. |
| ApplicationName | published | Name of the application to start (deprecated). |
| CommandLine | published | Command-line to execute (deprecated). |
| ConsoleTitle | published | Title of the console window. |
| CurrentDirectory | published | Working directory of the process. |
| Desktop | published | Desktop on which to start the process. |
| Environment | published | Environment variables for the new process. |
| ErrorDescriptor | published | |
| Executable | published | Executable name. Supersedes CommandLine and ApplicationName. |
| ExitCode read only | public | Exit code of the process. |
| ExitStatus read only | public | Exit status of the process. |
| FillAttribute | published | Color attributes of the characters in the console window (Windows only). |
| Handle read only | public | Handle of the process. |
| InheritHandles | public | Should the created process inherit the open handles of the current process. |
| Input read only | public | Stream connected to standard input of the process. |
| InputDescriptor | published | |
| Options | published | Options to be used when starting the process. |
| Output read only | public | Stream connected to standard output of the process. |
| OutputDescriptor | published | |
| Parameters | published | Command-line arguments. Supersedes CommandLine. |
| PipeBufferSize | published | Buffer size to be used when using pipes. |
| Priority | published | Priority at which the process is running. |
| ProcessHandle read only | public | Alias for Handle. |
| ProcessID read only | public | ID of the process. |
| RunCommandSleepTime | public | Sleep time between attempts to collect data. |
| Running read only | published | Determines whether the process is still running. |
| ShowWindow | published | Determines how the process main window is shown (Windows only). |
| SkipCommandLineQuotes | published | |
| StartupOptions | published | Additional (Windows) startup options. |
| Stderr read only | public | Stream connected to standard diagnostic output of the process. |
| ThreadHandle read only | public | Main process thread handle. |
| ThreadID read only | public | ID of the main process thread. |
| WindowColumns | published | Number of columns in console window (windows only). |
| WindowHeight | published | Height of the process main window. |
| WindowLeft | published | X-coordinate of the initial window (Windows only). |
| WindowRect | public | Positions for the main program window. |
| WindowRows | published | Number of rows in console window (Windows only). |
| WindowTop | published | Y-coordinate of the initial window (Windows only). |
| WindowWidth | published | Height of the process main window (Windows only). |
| XTermProgram | published | XTerm program to use (UNIX only). |
Methods¶
| Member | Visibility | Description |
|---|---|---|
| CloseInput | public | Close the input stream of the process. |
| CloseOutput | public | Close the output stream of the process. |
| CloseStderr | public | Close the error stream of the process. |
| Create | public | Create a new instance of the TProcess class. |
| Destroy | public | Destroy this instance of TProcess. |
| Execute | public | Execute the program with the given options. |
| ReadInputStream | public | Read available data from input stream. |
| Resume | public | Resume execution of a suspended process. |
| RunCommandLoop | public | Execute command and collect output in strings. |
| Suspend | public | Suspend a running process. |
| Terminate | public | Terminate a running process. |
| WaitOnExit | public | Wait for the program to stop executing. |
Events¶
| Member | Visibility | Description |
|---|---|---|
| OnForkEvent | public | Event triggered after fork occurred on Linux. |
| OnRunCommandEvent | public | Event handler, called when RunCommandLoop is executing. |