forked from mh-cbon/aghfabsowecwn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
38 lines (30 loc) · 981 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var aghfabsowecwn = require('./index.js');
var spawn = aghfabsowecwn.spawn;
var opts = {
stdio: 'pipe',
env:{'FORCE_COLOR':1, 'DEBUG': '*'}
}
// var child = spawn('sh', ['-c', 'ls -al && echo "stderr" >&2'], opts);
var child = spawn(process.argv[0], [__dirname + '/test/utils/stdin.js'], opts);
// var child = spawn('nop no such thing', [__dirname + '/test/utils/stdin.js'], opts);
child.on('close', function (code) {
console.log(arguments);
console.log('===> child close code=%s', code)
})
child.on('exit', function (code) {
console.log(arguments);
console.log('===> child exit code=%s', code)
})
child.on('error', function (error) {
console.log('===> child error=%s', error)
console.log('===> child error=%j', error)
})
child.stdout.pipe(process.stdout)
child.stderr.pipe(process.stderr)
child.stdin.write('some');
// child.stdin.end();
child.once('started', function () {
setTimeout(function () {
child.kill(); // triggers a SIGTERM.
}, 1000)
})