用node.js执行一个shell程序并传递参数

我想执行一个需要Node.js的任何params的shell程序

我怎样才能做到这一点 ?

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

要执行shell命令:

var sys = require('sys') var exec = require('child_process').exec; exec('command', function (error, stdout, stderr) {}); 

From: 使用node.js(childProcess)运行shell脚本 ,

使用参数'foo'在主文件夹中运行一个bar.sh程序:

 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); } });