Process and BaseProcess
The Process library provides solution to execute a command, to control its execution, to redirect its outputs and input.
BaseProcess library
Creation of process handlers
The main interfaces are BASE_PROCESS_FACTORY and BASE_PROCESS. The factory helps to instantiate a BASE_PROCESS object, which is the execution controller. The BASE_PROCESS object is used to configure the execution, to launch the execution, and check for the termination. It could also terminate the execution if wanted.
The factory interface provides 2 useful functions creating a BASE_PROCESS object:
-
process_launchertakes as parameters the file name of the executable, then the arguments as a list of strings, and an optional working directory. -
process_launcher_with_command_lineis similar toprocess_launcher, but takes the full command line, instead of executable filename and arguments.
The advantage of process_launcher is that you do not have to care about quoting the argument values.
Output redirection
On the BASE_PROCESS object, it is possible to configure the execution.
- It is possible to redirect the standard and error output, and also the input, for instance:
-
redirect_output_to_fileis used to record the execution output in a file -
redirect_error_to_same_as_outputis used to redirect the error output with the standard output -
redirect_input_to_fileis used to take the input from a file. - check other
redirect_*routines.
-
Platform-specific settings
| Feature | Description |
|---|---|
is_terminal_control_enabled | If True, the launched process will have terminal control over standard input, output and error. |
hidden | If True, the process will be launched silently (no console window will prompt out). |
separate_console | If True, the process will be launched with a new console instead of inheriting parent's console. |
detached_console | If True, the process will be launched without any console. |
Execution control
| Feature | Description |
|---|---|
launch | Launch the execution. |
terminate | Terminate launched execution. Check last_termination_successful after to see if terminate succeeded.
|
terminate_tree | Terminate process tree starting from current launched process. Check last_termination_successful after to see if terminate_tree succeeded. terminate_tree executes asynchronously. After calling terminate, call wait_to_exit to wait for process to exit.
|
wait_for_exit | Wait until process has exited. |
wait_for_exit_with_timeout (timeout: INTEGER) | Wait launched process to exit for at most timeout milliseconds. Check has_exited after to see if launched process has exited.
|
close | Close handles associated with child process. The process may continue running. If there is any input/output redirection to/from current process, it will be closed. |
Execution status
| Feature | Description |
|---|---|
id | Identifier of the last launched process. |
exit_code | Exit code of child process. It should be called after the process has exited. |
platform | It is a facility to know which is the current platform. |
launched | Has the process been launched? Check after a call to launch. |
is_running | Is the process still running (i.e launched and not exited)? |
has_exited | Has launched process exited and have allocated resources been cleaned up? |
Process library
The Process library is an extension of the BaseProcess library, the main interfaces are
-
PROCESS_FACTORYwhich inherits fromBASE_PROCESS_FACTORYand createsPROCESSobjects. -
PROCESSwhich inherits fromBASE_PROCESSand add agent based redirection.
The agent based redirections can be useful to process the execution output as it comes, and also to send data to the input.
