Skip to content

Commit 449f73b

Browse files
charmandervsemozhetbyt
authored andcommitted
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: #21516 Reviewed-By: Vse Mozhet Byt <[email protected]>
1 parent 02fd93d commit 449f73b

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

doc/api/child_process.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,6 @@ exec('echo "The \\$HOME variable is $HOME"');
180180
**Never pass unsanitized user input to this function. Any input containing shell
181181
metacharacters may be used to trigger arbitrary command execution.**
182182

183-
```js
184-
const { exec } = require('child_process');
185-
exec('cat *.js bad_file | wc -l', (error, stdout, stderr) => {
186-
if (error) {
187-
console.error(`exec error: ${error}`);
188-
return;
189-
}
190-
console.log(`stdout: ${stdout}`);
191-
console.log(`stderr: ${stderr}`);
192-
});
193-
```
194-
195183
If a `callback` function is provided, it is called with the arguments
196184
`(error, stdout, stderr)`. On success, `error` will be `null`. On error,
197185
`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
206194
stderr output. If `encoding` is `'buffer'`, or an unrecognized character
207195
encoding, `Buffer` objects will be passed to the callback instead.
208196

197+
```js
198+
const { exec } = require('child_process');
199+
exec('cat *.js missing_file | wc -l', (error, stdout, stderr) => {
200+
if (error) {
201+
console.error(`exec error: ${error}`);
202+
return;
203+
}
204+
console.log(`stdout: ${stdout}`);
205+
console.log(`stderr: ${stderr}`);
206+
});
207+
```
208+
209209
If `timeout` is greater than `0`, the parent will send the signal
210210
identified by the `killSignal` property (the default is `'SIGTERM'`) if the
211211
child runs longer than `timeout` milliseconds.

0 commit comments

Comments
 (0)