summaryrefslogtreecommitdiff
path: root/doc/api/child_process.md
diff options
context:
space:
mode:
authorVse Mozhet Byt <vsemozhetbyt@gmail.com>2016-12-03 07:36:19 +0200
committerMyles Borins <mylesborins@google.com>2017-01-31 17:07:44 -0500
commite53262cda94e324fba55a6537ddb91da1098183c (patch)
tree2ad4a66aa990ad241505b9c98b221537381b9de0 /doc/api/child_process.md
parent9988f0202558cc3282f4e5e87ad9d31db3cbf90f (diff)
downloadnode-new-e53262cda94e324fba55a6537ddb91da1098183c.tar.gz
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: https://github.com/nodejs/node/pull/10102 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Diffstat (limited to 'doc/api/child_process.md')
-rw-r--r--doc/api/child_process.md34
1 files changed, 17 insertions, 17 deletions
diff --git a/doc/api/child_process.md b/doc/api/child_process.md
index fdffa0fc5a..02f6a057e7 100644
--- a/doc/api/child_process.md
+++ b/doc/api/child_process.md
@@ -91,11 +91,11 @@ const spawn = require('child_process').spawn;
const bat = spawn('cmd.exe', ['/c', 'my.bat']);
bat.stdout.on('data', (data) => {
- console.log(data);
+ console.log(data.toString());
});
bat.stderr.on('data', (data) => {
- console.log(data);
+ console.log(data.toString());
});
bat.on('exit', (code) => {
@@ -113,7 +113,7 @@ exec('my.bat', (err, stdout, stderr) => {
});
// Script with spaces in the filename:
-const bat = spawn('"my script.cmd"', ['a', 'b'], { shell:true });
+const bat = spawn('"my script.cmd"', ['a', 'b'], { shell: true });
// or:
exec('"my script.cmd" a b', (err, stdout, stderr) => {
// ...
@@ -383,7 +383,7 @@ ps.on('close', (code) => {
});
grep.stdout.on('data', (data) => {
- console.log(`${data}`);
+ console.log(data.toString());
});
grep.stderr.on('data', (data) => {
@@ -467,8 +467,8 @@ const out = fs.openSync('./out.log', 'a');
const err = fs.openSync('./out.log', 'a');
const child = spawn('prg', [], {
- detached: true,
- stdio: [ 'ignore', out, err ]
+ detached: true,
+ stdio: [ 'ignore', out, err ]
});
child.unref();
@@ -850,7 +850,7 @@ as in this example:
'use strict';
const spawn = require('child_process').spawn;
-let child = spawn('sh', ['-c',
+const child = spawn('sh', ['-c',
`node -e "setInterval(() => {
console.log(process.pid, 'is alive')
}, 500);"`
@@ -1097,21 +1097,21 @@ const fs = require('fs');
const child_process = require('child_process');
const child = child_process.spawn('ls', {
- stdio: [
- 0, // Use parents stdin for child
- 'pipe', // Pipe child's stdout to parent
- fs.openSync('err.out', 'w') // Direct child's stderr to a file
- ]
+ stdio: [
+ 0, // Use parent's stdin for child
+ 'pipe', // Pipe child's stdout to parent
+ fs.openSync('err.out', 'w') // Direct child's stderr to a file
+ ]
});
-assert.equal(child.stdio[0], null);
-assert.equal(child.stdio[0], child.stdin);
+assert.strictEqual(child.stdio[0], null);
+assert.strictEqual(child.stdio[0], child.stdin);
assert(child.stdout);
-assert.equal(child.stdio[1], child.stdout);
+assert.strictEqual(child.stdio[1], child.stdout);
-assert.equal(child.stdio[2], null);
-assert.equal(child.stdio[2], child.stderr);
+assert.strictEqual(child.stdio[2], null);
+assert.strictEqual(child.stdio[2], child.stderr);
```
### child.stdout