http://zorba.io/modules/process

View as XML or JSON.

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.

Function Summary

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.

Functions

exec-command#1

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.

Parameters

cmd as string
command to be executed (without arguments)

Returns

object()
the result of the execution as an object

exec-command#2

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.

Parameters

cmd as string
command to be executed (without arguments)
args as string
the arguments passed to the executed command (e.g. "-la")

Returns

object()
the result of the execution as an object

exec#1

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.

Parameters

filename as string
the name of program to be executed

Returns

object()
the result of the execution as an object

exec#2

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.

Parameters

filename as string
the name of program to be executed
args as string
arguments to be passed to the executable

Returns

object()
the result of the execution as an object

exec#3

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.

Parameters

filename as string
the name of program to be executed
args as string
arguments to be passed to the executable
env as string
list of environment variables for the executable

Returns

object()
the result of the execution as an object