Skip to content

Commit 4534d1f

Browse files
committed
Added more examples
1 parent 12934bb commit 4534d1f

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
const { 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+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
});

0 commit comments

Comments
 (0)