Skip to content

Commit 3e9288e

Browse files
evanlucasMyles Borins
authored and
Myles Borins
committed
doc: fix exec example in child_process
Previously, the example was checking for error by strict equality to null. The error could be undefined though which would fail that check. PR-URL: #6660 Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Jeremy Whitlock <jwhitlock@apache.org>
1 parent 8b396e3 commit 3e9288e

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

doc/api/child_process.markdown

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ generated output.
139139

140140
```js
141141
const exec = require('child_process').exec;
142-
const child = exec('cat *.js bad_file | wc -l',
143-
(error, stdout, stderr) => {
144-
console.log(`stdout: ${stdout}`);
145-
console.log(`stderr: ${stderr}`);
146-
if (error !== null) {
147-
console.log(`exec error: ${error}`);
148-
}
142+
exec('cat *.js bad_file | wc -l', (error, stdout, stderr) => {
143+
if (error) {
144+
console.error(`exec error: ${error}`);
145+
return;
146+
}
147+
console.log(`stdout: ${stdout}`);
148+
console.log(`stderr: ${stderr}`);
149149
});
150150
```
151151

0 commit comments

Comments
 (0)