wilton.js  v202103141
 All Namespaces Functions
Functions
process Namespace Reference

wilton/process
OS process operations. More...

Functions

Number currentPid (Function|Undefined callback)
 Return the PID of the current process.
String killByPid (Number pid, Function|Undefined callback)
 Kill the process with the specified PID.
Number spawn (Object options, Function|Undefined callback)
 Spawn new OS-level process.
Number spawnShell (Array commands, Function|Undefined callback)
 Spawn new OS-level shell process.

Detailed Description

This module currently provides only one function: spawn() .

Usage example:

// spawn new process in background and return its pid
var pid = process.spawn({
executable: path/to/executable,
args: ["foo", "bar"],
outputFile: path/to/out/file,
awaitExit: false
});
// spawn new process, wait for it to exit, return exit code
var code = process.spawn({
executable: path/to/executable,
args: ["foo", "bar"],
outputFile: path/to/out/file,
awaitExit: true
});
// get pid of the current process
var pid = process.currentPid();
// kill process by pid
process.killByPid(pid);

Function Documentation

Number process::currentPid ( Function|Undefined  callback)

Returns the PID of the current process. Not supported on Android.

Parameters
callbackFunction|Undefined callback to receive result or error
Returns
Number PID of the current process
String process::killByPid ( Number  pid,
Function|Undefined  callback 
)

Teminates the process with the specified PID. Target process cannot prevent its termination. Not supported on Android.

Parameters
pidNumber PID of the process to terminate
callbackFunction|Undefined callback to receive result or error
Returns
String Empty string on successfull termination, error message otherwise.
Number process::spawn ( Object  options,
Function|Undefined  callback 
)

Spawns an OS-level process launching specified executable with the specified arguments.

Spawned process does not have STDIN connected. STDOUT and STDERR are redirected to (the same) specified file.

If awaitExit flag is enabled - waits for the spawned process to exit and returs its exit code.

Otherwise (default behaviour) returns immediately returning a pid of the spawned process.

Parameters
optionsObject configuration object, see possible options below
callbackFunction|Undefined callback to receive result or error
Returns
Number PID of started process or its exit code, if awaitExit is used

Options

  • executable String path to the executable file
  • args Array list of the arguments to provide to the executable
  • outputFile String|Undefined path to the file for the combined STDOUT and STDERRoutput
  • directory String|Undefined path to the working directory for the process, default value: the same working directory as parent process
  • awaitExit Boolean whether to wait for the spawned process to exit, false by default
Number process::spawnShell ( Array  commands,
Function|Undefined  callback 
)

Spawns an OS-level shell process launching OS-specific shell processor and waits for it to exit.

Note: use spawn instead of spawnShell whether possible.

Parameters
commandsArray list of commands to pass to OS shell processor
callbackFunction|Undefined callback to receive result or error
Returns
Number OS-specific output code