Browse Source

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: https://github.com/nodejs/node/pull/6660
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Jeremy Whitlock <jwhitlock@apache.org>
v4.x
Evan Lucas 9 years ago
committed by Myles Borins
parent
commit
3e9288e466
  1. 14
      doc/api/child_process.markdown

14
doc/api/child_process.markdown

@ -139,13 +139,13 @@ generated output.
```js
const exec = require('child_process').exec;
const child = exec('cat *.js bad_file | wc -l',
(error, stdout, stderr) => {
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
if (error !== null) {
console.log(`exec error: ${error}`);
}
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}`);
});
```

Loading…
Cancel
Save