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>
This commit is contained in:
parent
02fd93d91a
commit
449f73b7ff
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user