Skip to content

Commit bc28398

Browse files
charmandertargos
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 504c0cd commit bc28398

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

doc/api/child_process.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,6 @@ exec('echo "The \\$HOME variable is $HOME"');
177177
**Never pass unsanitized user input to this function. Any input containing shell
178178
metacharacters may be used to trigger arbitrary command execution.**
179179

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

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

0 commit comments

Comments
 (0)