Created
September 16, 2011 12:30
-
-
Save jinwei233/1222016 to your computer and use it in GitHub Desktop.
NodeJs执行系统命令
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var spawn = require('child_process').spawn; | |
var cmds = [["/c","dir"],["/c","java"],["/c","java","-jar"]] | |
cmds.forEach(function(v){ | |
v && exe(v); | |
}); | |
function exe(command){ | |
var cmd = spawn("cmd",command); | |
cmd.stdout.setEncoding("ASCII"); | |
cmd.stdout.on("data",function(data){ | |
console.log("------------------------------"); | |
console.log("exec",command); | |
console.log("stdout:"+data); | |
}); | |
cmd.stderr.on("data",function(data){ | |
console.log("------------------------------"); | |
console.log("stderr:"+data); | |
console.log("------------------------------"); | |
}); | |
cmd.on("exit",function(code){ | |
console.log("exited with code:"+code); | |
console.log("------------------------------"); | |
}); | |
}; | |
//中文注释 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment