The command to run.
List of string arguments.
Current working directory of the child process.
Environment key-value pairs.
Explicitly set the value of sent to the child process.
This will be set to if not specified.
Child's stdio configuration (see)
Prepare child to run independently of its parent process.
Specific behavior depends on the platform, see
Sets the user identity of the process (see)
Sets the group identity of the process (see)
If, runs inside of a shell.
A different shell can be specified as a string.
No quoting or escaping of arguments is done on Windows.
This is set to automatically when is specified.
The method spawns a new process using the given, with command line arguments in
If omitted, defaults to an empty array.
A third argument may be used to specify additional options, with these defaults:
Use to specify the working directory from which the process is spawned.
If not given, the default is to inherit the current working directory.
Use to specify environment variables that will be visible to the new process, the default is
values in will be ignored.
Example of running capturing and the exit code:
Example: A very elaborate way to run
Example of checking for failed
Certain platforms (macOS, Linux) will use the value of for the process title while others (Windows, SunOS) will use
Node.js currently overwrites with on startup, so in a Node.js child process will not match the parameter passed to from the parent, retrieve it with the property instead.
On Windows, setting to makes it possible for the child process to continue running after the parent exits.
The child will have its own console window.
Once enabled for a child process, it cannot be disabled
On non-Windows platforms, if is set to, the child process will be made the leader of a new process group and session.
Note that child processes may continue running after the parent exits regardless of whether they are detached or not.
See for more information.
By default, the parent will wait for the detached child to exit.
To prevent the parent from waiting for a given, use the method.
Doing so will cause the parent's event loop to not include the child in its reference count, allowing the parent to exit independently of the child, unless there is an established IPC channel between the child and parent.
When using the option to start a long-running process, the process will not stay running in the background after the parent exits unless it is provided with a configuration that is not connected to the parent.
If the parent's is inherited, the child will remain attached to the controlling terminal.
Example of a long-running process, by detaching and also ignoring its parent file descriptors, in order to ignore the parent's termination:
Alternatively one can redirect the child process' output into files:
The option is used to configure the pipes that are established between the parent and child process.
By default, the child's and are redirected to corresponding, and streams on the object.
This is equivalent to setting the equal to
For convenience, may be one of the following strings:
equivalent to (the default)
Otherwise, the value of is an array where each index corresponds to an fd in the child.
The fds 0, 1, and 2 correspond to and, respectively.
Additional fds can be specified to create additional pipes between the parent and child
The value is one of the following:
Create a pipe between the child process and the parent process
The parent end of the pipe is exposed to the parent as a property on the object as
Pipes creates for fds 0 - 2 are also available as and respectively.
Create an IPC channel for passing messages/file descriptors between parent and child.
A may have at most one IPC file descriptor
Setting this option enables the method.
If the child is a Node.js process, the presence of an IPC channel will enable and methods, as well as events within the child.
Accessing the IPC channel fd in any way other than or using the IPC channel with a child process that is not a Node.js instance is not supported.
Instructs Node.js to ignore the fd in the child.
While Node.js will always open fds 0 - 2 for the processes it spawns, setting the fd to will cause Node.js to open and attach it to the child's fd.
Share a readable or writable stream that refers to a tty, file, socket, or a pipe with the child process.
The stream's underlying file descriptor is duplicated in the child process to the fd that corresponds to the index in the array.
Note that the stream must have an underlying descriptor (file streams do not until the event has occurred).
The integer value is interpreted as a file descriptor that is currently open in the parent process.
It is shared with the child process, similar to how objects can be shared.
Use default value.
For fds 0, 1, and 2 (in other words, and) a pipe is created.
For fd 3 and up, the default is
Child will use parent's
Spawn child sharing only
Open an extra fd=4, to interact with programs presenting a startd-style interface.
It is worth noting that when an IPC channel is established between the parent and child processes, and the child is a Node.js process, the child is launched with the IPC channel unreferenced (using) until the child registers an event handler for the event or the event.
This allows the child to exit normally without the process being held open by the open IPC channel.
Synchronous Process Creation
The and methods are synchronous and WILL block the Node.js event loop, pausing execution of any additional code until the spawned process exits.
Blocking calls like these are mostly useful for simplifying general-purpose scripting tasks and for simplifying the loading/processing of application configuration at startup.
The value which will be passed as to the spawned process.
Supplying this value will override
by default will be output to the parent process' unless is specified.
In milliseconds the maximum amount of time the process is allowed to run.
The signal value to be used when the spawned process will be killed.
The encoding used for all stdio inputs and outputs.
The stdout from the command.
The method is generally identical to with the exception that the method will not return until the child process has fully closed.
When a timeout has been encountered and is sent, the method won't return until the process has completely exited.
If the child process intercepts and handles the signal and does not exit, the parent process will still wait until the child process has exited.
If the process times out or has a non-zero exit code, this method will throw an that will include the full result of the underlying