Running shell commands from node.js

33 views
Skip to first unread message

Ruchit Kadakia

unread,
Jul 26, 2016, 9:38:16 AM7/26/16
to nodejs
I am trying to run this command from node.js file

var sys = require('sys')

var exec = require('child_process').exec;


var child1 = exec("cd: /usr/local ", function (error, stdout, stderr) {

  sys.print('stdout: ' + stdout);

  sys.print('stderr: ' + stderr);

  if (error !== null) {

    console.log('exec error: ' + error);

  }

});


It is giving me error command not found whereas all  ls, pwd commands work well

Ryan Schmidt

unread,
Jul 26, 2016, 5:13:07 PM7/26/16
to nod...@googlegroups.com
Well, there shouldn't be a colon there. The command name is "cd", not "cd:". But just running "cd" isn't going to accomplish much, since exec runs in a separate shell. That separate shell will start, change to the directory, then exit, accomplishing nothing. What are you actually trying to do?


Reply all
Reply to author
Forward
0 new messages