Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bc28398

Browse filesBrowse 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 <vsemozhetbyt@gmail.com>
1 parent 504c0cd commit bc28398
Copy full SHA for bc28398

File tree

Expand file treeCollapse file tree

1 file changed

+12
-12
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+12
-12
lines changed
Open diff view settings
Collapse file

‎doc/api/child_process.md‎

Copy file name to clipboardExpand all lines: doc/api/child_process.md
+12-12Lines changed: 12 additions & 12 deletions
  • Display the source diff
  • Display the rich diff
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.