Skip to content

Commit e53262c

Browse files
vsemozhetbytMylesBorins
authored andcommittedJan 31, 2017
doc: modernize child_process example code
1. equal => strictEqual. 2. let => const for the variable that is not reassigned. 3. fix spaces. 4. stringify erroneous raw buffer outputs. 5. fix a typo. PR-URL: #10102 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
1 parent 9988f02 commit e53262c

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed
 

‎doc/api/child_process.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ const spawn = require('child_process').spawn;
9191
const bat = spawn('cmd.exe', ['/c', 'my.bat']);
9292

9393
bat.stdout.on('data', (data) => {
94-
console.log(data);
94+
console.log(data.toString());
9595
});
9696

9797
bat.stderr.on('data', (data) => {
98-
console.log(data);
98+
console.log(data.toString());
9999
});
100100

101101
bat.on('exit', (code) => {
@@ -113,7 +113,7 @@ exec('my.bat', (err, stdout, stderr) => {
113113
});
114114

115115
// Script with spaces in the filename:
116-
const bat = spawn('"my script.cmd"', ['a', 'b'], { shell:true });
116+
const bat = spawn('"my script.cmd"', ['a', 'b'], { shell: true });
117117
// or:
118118
exec('"my script.cmd" a b', (err, stdout, stderr) => {
119119
// ...
@@ -383,7 +383,7 @@ ps.on('close', (code) => {
383383
});
384384

385385
grep.stdout.on('data', (data) => {
386-
console.log(`${data}`);
386+
console.log(data.toString());
387387
});
388388

389389
grep.stderr.on('data', (data) => {
@@ -467,8 +467,8 @@ const out = fs.openSync('./out.log', 'a');
467467
const err = fs.openSync('./out.log', 'a');
468468

469469
const child = spawn('prg', [], {
470-
detached: true,
471-
stdio: [ 'ignore', out, err ]
470+
detached: true,
471+
stdio: [ 'ignore', out, err ]
472472
});
473473

474474
child.unref();
@@ -850,7 +850,7 @@ as in this example:
850850
'use strict';
851851
const spawn = require('child_process').spawn;
852852

853-
let child = spawn('sh', ['-c',
853+
const child = spawn('sh', ['-c',
854854
`node -e "setInterval(() => {
855855
console.log(process.pid, 'is alive')
856856
}, 500);"`
@@ -1097,21 +1097,21 @@ const fs = require('fs');
10971097
const child_process = require('child_process');
10981098

10991099
const child = child_process.spawn('ls', {
1100-
stdio: [
1101-
0, // Use parents stdin for child
1102-
'pipe', // Pipe child's stdout to parent
1103-
fs.openSync('err.out', 'w') // Direct child's stderr to a file
1104-
]
1100+
stdio: [
1101+
0, // Use parent's stdin for child
1102+
'pipe', // Pipe child's stdout to parent
1103+
fs.openSync('err.out', 'w') // Direct child's stderr to a file
1104+
]
11051105
});
11061106

1107-
assert.equal(child.stdio[0], null);
1108-
assert.equal(child.stdio[0], child.stdin);
1107+
assert.strictEqual(child.stdio[0], null);
1108+
assert.strictEqual(child.stdio[0], child.stdin);
11091109

11101110
assert(child.stdout);
1111-
assert.equal(child.stdio[1], child.stdout);
1111+
assert.strictEqual(child.stdio[1], child.stdout);
11121112

1113-
assert.equal(child.stdio[2], null);
1114-
assert.equal(child.stdio[2], child.stderr);
1113+
assert.strictEqual(child.stdio[2], null);
1114+
assert.strictEqual(child.stdio[2], child.stderr);
11151115
```
11161116

11171117
### child.stdout

0 commit comments

Comments
 (0)