child_process
Last updated
Was this helpful?
Last updated
Was this helpful?
exec
Spawns a shell then executes the command
within that shell, buffering any generated output. The command
string passed to the exec function is processed directly by the shell, and special characters (vary based on ) need to be dealt with accordingly:
Never pass unsanitized user input to this function. Any input containing shell metacharacters may be used to trigger arbitrary command execution.
The stdout
and stderr
arguments passed to the stream will contain the stdout and stderr output of the child process. By default, Node.js will decode the output as UTF-8 and pass strings to the callback. The encoding
option can be used to specify the character encoding used to decode the stdout and stderr output. If encoding
is 'buffer'
, or an unrecognized character encoding, Buffer
objects will be passed to the callback instead.
If timeout
is greater than 0
, the parent will send the signal identified by the killSignal
property (the default is 'SIGTERM'
) if the child runs longer than timeout
milliseconds.
execFile
The stdout
and stderr
arguments passed to the stream will contain the stdout and stderr output of the child process. By default, Node.js will decode the output as UTF-8 and pass strings to the callback. The encoding
option can be used to specify the character encoding used to decode the stdout and stderr output. If encoding
is 'buffer'
, or an unrecognized character encoding, Buffer
objects will be passed to the callback instead.
If the shell
option is enabled, do not pass unsanitized user input to this function. Any input containing shell metacharacters may be used to trigger arbitrary command execution.
Unlike the POSIX system call, exec()
does not replace the existing process and uses a shell to execute the command.
The execFile()
function is similar to except that it does not spawn a shell by default. Rather, the specified executable file
is spawned directly as a new process making it slightly more efficient than .
The same options as are supported. Since a shell is not spawned, behaviors such as I/O redirection and file globbing are not supported.