-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd.js
42 lines (36 loc) · 839 Bytes
/
cmd.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
const { exec, execSync } = require('child_process');
const commandline={
run:runCommand,
runSync:runSync,
};
function runCommand(command,callback){
return exec(
command,
(
function(){
return function(err,data,stderr){
if(!callback)
return;
callback(err, data, stderr);
}
}
)(callback)
);
}
function runSync(command){
try {
return {
data: execSync(command).toString(),
err: null,
stderr: null
}
}
catch (error) {
return {
data: null,
err: error.stderr.toString(),
stderr: error.stderr.toString()
}
}
}
module.exports=commandline;