From bc28398cbef9e79c77f7bc073aba2faf3b7fd135 Mon Sep 17 00:00:00 2001 From: Charmander <~@charmander.me> Date: Sun, 24 Jun 2018 17:12:59 -0700 Subject: [PATCH] doc: separate unrelated info about child_process.exec() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit “Never pass unsanitized user input to this function” is followed by a code example with `bad_file`, but they aren’t related. Avoid confusion by moving the example and giving `bad_file` a more specific name. PR-URL: https://github.com/nodejs/node/pull/21516 Reviewed-By: Vse Mozhet Byt --- doc/api/child_process.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/doc/api/child_process.md b/doc/api/child_process.md index 51290bf251e3a8..e419d9693d13eb 100644 --- a/doc/api/child_process.md +++ b/doc/api/child_process.md @@ -177,18 +177,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 @@ -203,6 +191,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.