Method Process.run()
- Method run
mapping
run(string
|array
(string
)cmd
,void
|mapping
modifiers
)- Description
Easy and lazy way of using Process.Process that runs a process and returns a mapping with the output and exit code without having to make sure you read nonblocking yourself.
- Parameter
args
Either a command line array, as the command_args argument to create_process(), or a string that will be splitted into a command line array by calling split_quoted_string() in an operating system dependant mode.
- Parameter
modifiers
It takes all the modifiers Process.Process accepts, with the exception of stdout and stderr. Each must be either absent, or a function accepting a string; if present, the functions will be called whenever output is made on the corresponding stream, otherwise the data will be collected and returned in the result mapping.
If
modifiers->stdin
is set to a string it will automatically be converted to a pipe that is fed to stdin of the started process.- See also
- Returns
"stdout"
:string
Everything the process wrote on stdout, unless a stdout function was provided.
"stderr"
:string
Everything the process wrote on stderr, similarly.
"exitcode"
:int
The process' exitcode.
- Note
As the entire output of stderr and stdout is stored in the returned mapping it could potentially grow until memory runs out. It is therefore advisable to set up rlimits if the output has a potential to be very large, or else provide functions to handle partial data.
- Example
Process.run( ({ "ls", "-l" }) ); Process.run( ({ "ls", "-l" }), ([ "cwd":"/etc" ]) ); Process.run( "ls -l" ); Process.run( "awk -F: '{print $2}'", ([ "stdin":"foo:2\nbar:17\n" ]) );