-
Notifications
You must be signed in to change notification settings - Fork 0
/
asyncProcessExecutor.js
60 lines (56 loc) · 1.4 KB
/
asyncProcessExecutor.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var trim = require('trim'),
child = require('child_process'),
Encoding = {
encoding: 'utf8'
},
lineFilter = function(s) {
return s.split('\n').map(function(l) {
return trim(l);
}).filter(function(l) {
return l.length > 3;
});
};
var nexpect = require('nexpect');
nexpect.spawn("echo", ["hello"])
.expect("hello")
.run(function(err, stdout, exitcode) {
if (!err) {
console.log("hello was echoed");
}
});
nexpect.spawn("ls -la /tmp/undefined", {
stream: 'stderr'
})
.expect("No such file or directory")
.run(function(err) {
if (!err) {
console.log("checked that file doesn't exists");
}
});
nexpect.spawn("node --interactive")
.expect(">")
.sendline("console.log('testing')")
.expect("testing")
.sendline("process.exit()")
.run(function(err) {
if (!err) {
console.log("node process started, console logged, process exited");
} else {
console.log(err)
}
});
/*
module.exports = {
execJson: function(c) {
process.exit();
return JSON.parse(child.execSync(c).toString());
},
execSyncLines: function(c) {
return lineFilter(child.execSync(c, Encoding));
},
execRaw: function(c) {
process.exit();
return child.execSync(c);
}
};
*/