var sys = require(\'sys\'),
exec = require(\'child_process\').exec;
exec(\"cd /home/ubuntu/distro\", function(err, stdout, stderr) {
console.log(\"cd: \" +
Your shell IS executing cd
but it's just that each shell throws away it's working directory after it's finished. Hence you're back at square one.
In your case, you don't need to call exec() more than once. You can make sure your cmd
variable contains multiple instructions instead of 1. CD will work in this case.
var cmd = `ls
cd foo
ls`
var exec = require('child_process').exec;
exec(cmd, function(err, stdout, stderr) {
console.log(stdout);
})
Note: This code should work on Linux but not Windows. See here