This module provides functions to create a native process and return the result (i.e. exit code, result on standard out and error) of executing the given file or command.
Example:
import module namespace p = "http://zorba.io/modules/process"; p:exec("ls")
Potential result:
{ "exit-code": 0, "stdout": "myfile.txt", "stderr": "" }
The exec-command set of functions allows execution of commands through the command line interpreter of the operating system, such as "sh" on Unix systems or "cmd.exe" on Windows.
For POSIX compliant platforms the functions return 128 + termination signal code of the process as their exit-code. On Windows platforms, the exit-code is the return value of the process or the exit or terminate process specified value.
exec-command
($cmd as string) as object() external
Executes the specified string command in a separate process. |
exec-command
($cmd as string, $args as string*) as object() external
Executes the specified string command in a separate process. |
exec
($filename as string) as object() external
Executes the specified program in a separate process. |
exec
($filename as string, $args as string*) as object() external
Executes the specified program in a separate process. |
exec
($filename as string, $args as string*, $env as string*) as object() external
Executes the specified program in a separate process. |
declare %an:sequential function p:exec-command($cmd as string) as object() external
Executes the specified string command in a separate process.
This function does not allow arguments to be passed to the command.
declare %an:sequential function p:exec-command($cmd as string, $args as string*) as object() external
Executes the specified string command in a separate process.
Each of the strings in the sequence passed in as the second argument is passed as an argument to the executed command.
declare %an:sequential function p:exec($filename as string) as object() external
Executes the specified program in a separate process.
This function does not allow arguments to be passed to the command. The $filename parameter can contain the full path to the executable. On Unix systems, if the specified filename does not contain a slash "/", the function duplicates the actions of the shell in searching for an executable file. The file is sought in the colon-separated list of directory pathnames specified in the PATH environment variable. If this variable isn't defined, the path list defaults to the current directory followed by the list of directories returned by the operating system.
declare %an:sequential function p:exec($filename as string, $args as string*) as object() external
Executes the specified program in a separate process.
The $filename parameter can contain the full path to the executable. On Unix systems, if the specified filename does not contain a slash "/", the function duplicates the actions of the shell in searching for an executable file. The file is sought in the colon-separated list of directory pathnames specified in the PATH environment variable. If this variable isn't defined, the path list defaults to the current directory followed by the list of directories returned by the operating system. The $args parameters will be passed to the executable file as arguments.
declare %an:sequential function p:exec($filename as string, $args as string*, $env as string*) as object() external
Executes the specified program in a separate process.
The $filename parameter can contain the full path to the executable. On Unix systems, if the specified filename does not contain a slash "/", the function duplicates the actions of the shell in searching for an executable file. The file is sought in the colon-separated list of directory pathnames specified in the PATH environment variable. If this variable isn't defined, the path list defaults to the current directory followed by the list of directories returned by the operating system.
The $env allows defining and passing environment variables to the target process. They should be in the form "ENVVAR=value" where "ENVVAR" is the name of the environment variable and "value' is the string value to set it to.