Node.js Shell Script And Arguments

后端 未结 3 1802
再見小時候
再見小時候 2020-11-28 21:18

I need to execute a bash script in node.js. Basically, the script will create user account on the system. I came across this example which gives me an idea how to go about i

3条回答
  •  北海茫月
    2020-11-28 22:09

    var exec = require('child_process').exec;
    
    var child = exec('cat *.js | wc -l', function(error, stdout, stderr) {
      if (error) console.log(error);
      process.stdout.write(stdout);
      process.stderr.write(stderr);
    });
    

    This way is nicer because console.log will print blank lines.

提交回复
热议问题