ChildProcess
A running program is a process. A process spawned from another process is known as a child process.
This module allow you to spawn child processes.
Initialization
This value represents the permission to spawn child processes.
Only code you trust should have access to this value.
Initialize the ChildProcess subsystem, which gains you the permission to
spawn child processes.
Running processes
Options to customize the execution of a child process created with run.
shellis the shell to run the process in (if any)workingDirectoryspecifies the working directory of the processenvironmentVariablesspecifies the environment variables the process has access tomaximumBytesWrittenToStreamsspecifies an upper bound of bytes that can be returned from the processrunDurationspecifies a maximum amount of time a process is allowed to run before exiting
A nice default set of options for the run function
Which shell should the child process run in?
NoShellexecutes the process directly, without any shell. A little bit more efficient, but you lose some convinience as shell behaviour (like glob patterns) isn't available for argumentsDefaultShellexecutes the process in the default shell for the currently running systemCustomShellexecutes the process in the specified shell.
What should be the working directory of the process?
InheritWorkingDirectoryinherits the working directory from its parentSetWorkingDirectorysets the working directory to the specified value (doesn't affect parent)
What should be the environment variables of the process?
InheritEnvironmentVariablesinherits the environment variables from its parentMergeWithEnvironmentVariablesinherits the environment variables from its parent, with the specified modificationsReplaceEnvironmentVariablessets the environment variables to the specified dictionary
How long is the process allowed to run before it's forcefully terminated?
NoLimitmeans it can run foreverMillisecondssets the limit to the specified number of milliseconds
Execute a process with a given name, arguments and options, and wait for it to terminate.
run permission "cat" [ "my_file" ] defaultRunOptions
Return value when a process terminates without error
Return value when a process terminates due to an error.
Running a child process can either fail due to a system error, like the requested program not being installed, or due to an error in the program itself, like calling it with arguments it doesn't recognize.
Spawning processes
Spawn a process with a given name, arguments and options, and let it run in the background. This is mostly helpful for starting long-running processes.
spawn permission "tail" [ "my_file" ] mySpawnOptions
Options to customize the execution of a child process created with spawn.
shellis the shell to run the process in (if any)workingDirectoryspecifies the working directory of the processenvironmentVariablesspecifies the environment variables the process has access torunDurationspecifies a maximum amount of time a process is allowed to run before exitingconnectionlet's you specify how the new process is connected to the application, and which message to receive when the process startsonExitis the message that is triggered when the process exits. The message receives the exit code.
Streams that can be used to communicate with a spawned child process.
What relation should the newly spawned process have with the running application?
Integratedmeans that the spawned process shares the stdin, stdout and stderr streams.Externalmeans that a new streams are created for stdin, stdout and stderr and passed to the application, which can use those streams for communicating with the new process.Ignoredmeans the same asExternal, but anything written to stdin, stdout and stderr is discarded/ignored.Detachedmeans the same asIgnored, but that the application will exit even if the child process hasn't finished executing.
A nice default set of options for the spawn function.