diff options
author | Charmander <~@charmander.me> | 2018-06-24 17:12:59 -0700 |
---|---|---|
committer | Vse Mozhet Byt <vsemozhetbyt@gmail.com> | 2018-06-27 20:39:22 +0300 |
commit | 449f73b7ffd60e7dd140b360e4b53dc2428f4aef (patch) | |
tree | 576eb9374a145f4bf960974520e0ce2d6d320606 /doc/api/child_process.md | |
parent | 02fd93d91a3a5e29ab42d812fdab46ec61a07830 (diff) | |
download | android-node-v8-449f73b7ffd60e7dd140b360e4b53dc2428f4aef.tar.gz android-node-v8-449f73b7ffd60e7dd140b360e4b53dc2428f4aef.tar.bz2 android-node-v8-449f73b7ffd60e7dd140b360e4b53dc2428f4aef.zip |
doc: separate unrelated info about child_process.exec()
“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 <vsemozhetbyt@gmail.com>
Diffstat (limited to 'doc/api/child_process.md')
-rw-r--r-- | doc/api/child_process.md | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/doc/api/child_process.md b/doc/api/child_process.md index e71bf89f91..a2e6bb5365 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. |