diff --git a/doc/api/child_process.md b/doc/api/child_process.md index e71bf89f9133bd..a2e6bb5365cfb3 100644 --- a/doc/api/child_process.md +++ b/doc/api/child_process.md @@ -180,18 +180,6 @@ exec('echo "The \\$HOME variable is $HOME"'); **Never pass unsanitized user input to this function. Any input containing shell metacharacters may be used to trigger arbitrary command execution.** -```js -const { exec } = require('child_process'); -exec('cat *.js bad_file | wc -l', (error, stdout, stderr) => { - if (error) { - console.error(`exec error: ${error}`); - return; - } - console.log(`stdout: ${stdout}`); - console.log(`stderr: ${stderr}`); -}); -``` - If a `callback` function is provided, it is called with the arguments `(error, stdout, stderr)`. On success, `error` will be `null`. On error, `error` will be an instance of [`Error`][]. The `error.code` property will be @@ -206,6 +194,18 @@ 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. +```js +const { exec } = require('child_process'); +exec('cat *.js missing_file | wc -l', (error, stdout, stderr) => { + if (error) { + console.error(`exec error: ${error}`); + return; + } + console.log(`stdout: ${stdout}`); + console.log(`stderr: ${stderr}`); +}); +``` + 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.