var sys = require('sys'),
exec = require('child_process').exec;
exec("cd /home/ubuntu/distro", function(err, stdout, stderr) {
console.log("cd: " + err + " : " + stdout);
exec("pwd", function(err, stdout, stderr) {
console.log("pwd: " + err + " : " + stdout);
exec("git status", function(err, stdout, stderr) {
console.log("git status returned " ); console.log(err);
})
})
})
cd: null :
pwd: null : /
git status returned
{ [Error: Command failed: fatal: Not a git repository (or any of the parent directories): .git ] killed: false, code: 128, signal: null }
nodeJS的exec方法在执行"cd "命令时会出现问题。如下所示,pwd命令可以正常执行,git status命令尝试执行但由于没有在git目录中执行而失败,但是cd命令失败了,导致其他命令无法成功执行。在nodeJS shell和nodeJS+ExpressJS webserver中都进行了尝试。