@@ -17,7 +17,7 @@ ls.stdout.on('data', (data) => {
17
17
});
18
18
19
19
ls .stderr .on (' data' , (data ) => {
20
- console .log (` stderr: ${ data} ` );
20
+ console .error (` stderr: ${ data} ` );
21
21
});
22
22
23
23
ls .on (' close' , (code ) => {
@@ -93,7 +93,7 @@ When running on Windows, `.bat` and `.cmd` files can be invoked using
93
93
spaces it needs to be quoted.
94
94
95
95
``` js
96
- // On Windows Only ...
96
+ // On Windows Only...
97
97
const { spawn } = require (' child_process' );
98
98
const bat = spawn (' cmd.exe' , [' /c' , ' my.bat' ]);
99
99
@@ -102,7 +102,7 @@ bat.stdout.on('data', (data) => {
102
102
});
103
103
104
104
bat .stderr .on (' data' , (data ) => {
105
- console .log (data .toString ());
105
+ console .error (data .toString ());
106
106
});
107
107
108
108
bat .on (' exit' , (code ) => {
@@ -171,10 +171,10 @@ need to be dealt with accordingly:
171
171
``` js
172
172
exec (' "/path/to/test file/test.sh" arg1 arg2' );
173
173
// Double quotes are used so that the space in the path is not interpreted as
174
- // multiple arguments
174
+ // a delimiter of multiple arguments.
175
175
176
176
exec (' echo "The \\ $HOME variable is $HOME"' );
177
- // The $HOME variable is escaped in the first instance, but not in the second
177
+ // The $HOME variable is escaped in the first instance, but not in the second.
178
178
```
179
179
180
180
** Never pass unsanitized user input to this function. Any input containing shell
@@ -202,7 +202,7 @@ exec('cat *.js missing_file | wc -l', (error, stdout, stderr) => {
202
202
return ;
203
203
}
204
204
console .log (` stdout: ${ stdout} ` );
205
- console .log (` stderr: ${ stderr} ` );
205
+ console .error (` stderr: ${ stderr} ` );
206
206
});
207
207
```
208
208
@@ -218,7 +218,7 @@ a `Promise` for an `Object` with `stdout` and `stderr` properties. The returned
218
218
` ChildProcess ` instance is attached to the ` Promise ` as a ` child ` property. In
219
219
case of an error (including any error resulting in an exit code other than 0), a
220
220
rejected promise is returned, with the same ` error ` object given in the
221
- callback, but with an additional two properties ` stdout ` and ` stderr ` .
221
+ callback, but with two additional properties ` stdout ` and ` stderr ` .
222
222
223
223
``` js
224
224
const util = require (' util' );
@@ -227,7 +227,7 @@ const exec = util.promisify(require('child_process').exec);
227
227
async function lsExample () {
228
228
const { stdout , stderr } = await exec (' ls' );
229
229
console .log (' stdout:' , stdout);
230
- console .log (' stderr:' , stderr);
230
+ console .error (' stderr:' , stderr);
231
231
}
232
232
lsExample ();
233
233
```
@@ -300,7 +300,7 @@ a `Promise` for an `Object` with `stdout` and `stderr` properties. The returned
300
300
` ChildProcess ` instance is attached to the ` Promise ` as a ` child ` property. In
301
301
case of an error (including any error resulting in an exit code other than 0), a
302
302
rejected promise is returned, with the same ` error ` object given in the
303
- callback, but with an additional two properties ` stdout ` and ` stderr ` .
303
+ callback, but with two additional properties ` stdout ` and ` stderr ` .
304
304
305
305
``` js
306
306
const util = require (' util' );
@@ -458,7 +458,7 @@ ls.stdout.on('data', (data) => {
458
458
});
459
459
460
460
ls .stderr .on (' data' , (data ) => {
461
- console .log (` stderr: ${ data} ` );
461
+ console .error (` stderr: ${ data} ` );
462
462
});
463
463
464
464
ls .on (' close' , (code ) => {
@@ -478,7 +478,7 @@ ps.stdout.on('data', (data) => {
478
478
});
479
479
480
480
ps .stderr .on (' data' , (data ) => {
481
- console .log (` ps stderr: ${ data} ` );
481
+ console .error (` ps stderr: ${ data} ` );
482
482
});
483
483
484
484
ps .on (' close' , (code ) => {
@@ -493,7 +493,7 @@ grep.stdout.on('data', (data) => {
493
493
});
494
494
495
495
grep .stderr .on (' data' , (data ) => {
496
- console .log (` grep stderr: ${ data} ` );
496
+ console .error (` grep stderr: ${ data} ` );
497
497
});
498
498
499
499
grep .on (' close' , (code ) => {
@@ -510,7 +510,7 @@ const { spawn } = require('child_process');
510
510
const subprocess = spawn (' bad_command' );
511
511
512
512
subprocess .on (' error' , (err ) => {
513
- console .log (' Failed to start subprocess.' );
513
+ console .error (' Failed to start subprocess.' );
514
514
});
515
515
```
516
516
@@ -609,8 +609,8 @@ pipes between the parent and child. The value is one of the following:
609
609
610
610
1 . ` 'pipe' ` - Create a pipe between the child process and the parent process.
611
611
The parent end of the pipe is exposed to the parent as a property on the
612
- ` child_process ` object as [ ` subprocess.stdio[fd] ` ] [ `stdio` ] . Pipes created
613
- for fds 0 - 2 are also available as [ ` subprocess.stdin ` ] [ ] ,
612
+ ` child_process ` object as [ ` subprocess.stdio[fd] ` ] [ `subprocess. stdio` ] . Pipes
613
+ created for fds 0 - 2 are also available as [ ` subprocess.stdin ` ] [ ] ,
614
614
[ ` subprocess.stdout ` ] [ ] and [ ` subprocess.stderr ` ] [ ] , respectively.
615
615
2 . ` 'ipc' ` - Create an IPC channel for passing messages/file descriptors
616
616
between parent and child. A [ ` ChildProcess ` ] [ ] may have at most one IPC
@@ -648,10 +648,10 @@ pipes between the parent and child. The value is one of the following:
648
648
``` js
649
649
const { spawn } = require (' child_process' );
650
650
651
- // Child will use parent's stdios
651
+ // Child will use parent's stdios.
652
652
spawn (' prg' , [], { stdio: ' inherit' });
653
653
654
- // Spawn child sharing only stderr
654
+ // Spawn child sharing only stderr.
655
655
spawn (' prg' , [], { stdio: [' pipe' , ' pipe' , process .stderr ] });
656
656
657
657
// Open an extra fd=4, to interact with programs presenting a
@@ -1033,7 +1033,7 @@ process of being received. This will most often be triggered immediately after
1033
1033
calling ` subprocess.disconnect() ` .
1034
1034
1035
1035
When the child process is a Node.js instance (e.g. spawned using
1036
- [ ` child_process.fork() ` ] ), the ` process.disconnect() ` method can be invoked
1036
+ [ ` child_process.fork() ` ] [ ] ), the ` process.disconnect() ` method can be invoked
1037
1037
within the child process to close the IPC channel as well.
1038
1038
1039
1039
### subprocess.kill([ signal] )
@@ -1056,7 +1056,7 @@ grep.on('close', (code, signal) => {
1056
1056
` child process terminated due to receipt of signal ${ signal} ` );
1057
1057
});
1058
1058
1059
- // Send SIGHUP to process
1059
+ // Send SIGHUP to process.
1060
1060
grep .kill (' SIGHUP' );
1061
1061
```
1062
1062
@@ -1092,7 +1092,7 @@ const subprocess = spawn(
1092
1092
);
1093
1093
1094
1094
setTimeout (() => {
1095
- subprocess .kill (); // Does not terminate the node process in the shell
1095
+ subprocess .kill (); // Does not terminate the Node.js process in the shell.
1096
1096
}, 2000 );
1097
1097
```
1098
1098
@@ -1291,12 +1291,12 @@ const special = fork('subprocess.js', ['special']);
1291
1291
const server = require (' net' ).createServer ({ pauseOnConnect: true });
1292
1292
server .on (' connection' , (socket ) => {
1293
1293
1294
- // If this is special priority
1294
+ // If this is special priority...
1295
1295
if (socket .remoteAddress === ' 74.125.127.100' ) {
1296
1296
special .send (' socket' , socket);
1297
1297
return ;
1298
1298
}
1299
- // This is normal priority
1299
+ // This is normal priority.
1300
1300
normal .send (' socket' , socket);
1301
1301
});
1302
1302
server .listen (1337 );
@@ -1384,9 +1384,9 @@ const child_process = require('child_process');
1384
1384
1385
1385
const subprocess = child_process .spawn (' ls' , {
1386
1386
stdio: [
1387
- 0 , // Use parent's stdin for child
1388
- ' pipe' , // Pipe child's stdout to parent
1389
- fs .openSync (' err.out' , ' w' ) // Direct child's stderr to a file
1387
+ 0 , // Use parent's stdin for child.
1388
+ ' pipe' , // Pipe child's stdout to parent.
1389
+ fs .openSync (' err.out' , ' w' ) // Direct child's stderr to a file.
1390
1390
]
1391
1391
});
1392
1392
@@ -1499,6 +1499,7 @@ unavailable.
1499
1499
[ `subprocess.send()` ] : #child_process_subprocess_send_message_sendhandle_options_callback
1500
1500
[ `subprocess.stderr` ] : #child_process_subprocess_stderr
1501
1501
[ `subprocess.stdin` ] : #child_process_subprocess_stdin
1502
+ [ `subprocess.stdio` ] : #child_process_subprocess_stdio
1502
1503
[ `subprocess.stdout` ] : #child_process_subprocess_stdout
1503
1504
[ `util.promisify()` ] : util.html#util_util_promisify_original
1504
1505
[ Default Windows Shell ] : #child_process_default_windows_shell
0 commit comments