nodeJS exec nie działa dla cmd powłoki „cd”
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 nie działa dla cmd powłoki „cd”. Jak widać poniżej, pwd działa, status git próbuje działać, ale nie działa, ponieważ nie jest wykonywany w katalogu git, ale cd cmd nie powiedzie się, zatrzymując dalsze pomyślne wykonywanie innych cmds. Wypróbowano powłokę nodeJS oraz serwer WWW nodeJS + ExpressJS.