Execute an shell program with node.js and pass params [closed]

倖福魔咒の 提交于 2019-12-01 07:37:38

问题


I would like to execute an shell program who require any params with Node.js

How can I do that ?


回答1:


From: http://www.dzone.com/snippets/execute-unix-command-nodejs

To execute shell commands:

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

exec('command', function (error, stdout, stderr) {});

From: Run shell script with node.js (childProcess),

To run a program bar.sh in your home folder with the argument 'foo':

var foo = 'foo';

exec('~/bar.sh ' + foo,
  function (error, stdout, stderr) {
    if (error !== null) {
      console.log(error);
    } else {
    console.log('stdout: ' + stdout);
    console.log('stderr: ' + stderr);
    }
});


来源:https://stackoverflow.com/questions/30915406/execute-an-shell-program-with-node-js-and-pass-params

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!