child_process 调用shell脚本 好像又打开了一扇窗
发布于 7 年前 作者 Rock-1 4598 次浏览 来自 分享

demo.js

const callfile = require('child_process');
const newpassword = 'newpwd';
callfile.exec('./a.sh one two three',function (err, stdout, stderr) {
    console.dir(arguments);
});

a.sh

echo "执行的文件名:$0";
echo "第一个参数为:$1";
echo "第二个参数为:$2";
echo "第三个参数为:$3";

输出

{ '0': null,
  '1': '第一个参数为:one\n第二个参数为:two\n第三个参数为:three\n',
  '2': '' }

回到顶部