File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11const { spawn } = require ( 'child_process' ) ;
2+ const ls = spawn ( 'ls' , [ '-l' ] ) ;
23
3- const child = spawn ( 'pwd' ) ;
4-
5- child . on ( 'exit' , function ( code , signal ) {
6- console . log ( `child process exited with code ${ code } and signal ${ signal } ` ) ;
4+ ls . stdout . on ( 'data' , ( data ) => {
5+ console . log ( `stdout: ${ data } ` ) ;
76} ) ;
87
9- child . on ( 'message ' , function ( message ) {
10- console . log ( `child process messaged with message ${ message } `) ;
8+ ls . stderr . on ( 'data ' , ( data ) => {
9+ console . error ( `stderr: ${ data } `) ;
1110} ) ;
1211
13- spawn ( 'git ', [ 'log' ] ) . stdout . pipe ( process . stdout )
14- spawn ( 'ls' ) . stdout . pipe ( process . stdout )
15-
12+ ls . on ( 'close ', ( code ) => {
13+ console . log ( `child process exited with code ${ code } ` ) ;
14+ } ) ;
Original file line number Diff line number Diff line change 1+ const { spawn } = require ( 'child_process' ) ;
2+ const ls = spawn ( 'ls' , [ '-l' ] ) ;
3+ const wc = spawn ( 'wc' )
4+
5+ // pipe output from ls as input to wc
6+ ls . stdout . pipe ( wc . stdin )
7+
8+ wc . stdout . on ( 'data' , ( data ) => {
9+ console . log ( `wc stdout: ${ data } ` ) ;
10+ } ) ;
11+
12+ wc . stderr . on ( 'data' , ( data ) => {
13+ console . error ( `wc stderr: ${ data } ` ) ;
14+ } ) ;
15+
16+ wc . on ( 'close' , ( code ) => {
17+ console . log ( `wc child process wc exited with code ${ code } ` ) ;
18+ } ) ;
You can’t perform that action at this time.
0 commit comments