Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用node.js执行脚本shell_Node.js_Shell_Child Process - Fatal编程技术网

如何使用node.js执行脚本shell

如何使用node.js执行脚本shell,node.js,shell,child-process,Node.js,Shell,Child Process,我试图使用node.js执行脚本shell。我使用的是子进程,但当我执行.js文件时,脚本shell不会被执行。这个函数有什么问题 const { exec } = require('child_process'); exec('/home/nadhem/TradeFinance/Backend/SmartContract/approveLOC.sh', (err, stdout, stderr) => { if (err) { // node couldn't execut

我试图使用node.js执行脚本shell。我使用的是子进程,但当我执行.js文件时,脚本shell不会被执行。这个函数有什么问题

const { exec } = require('child_process');
exec('/home/nadhem/TradeFinance/Backend/SmartContract/approveLOC.sh', 
(err, stdout, stderr) => {
  if (err) {
    // node couldn't execute the command
    return;
  }

  // the *entire* stdout and stderr (buffered)
  console.log(`stdout: ${stdout}`);
  console.log(`stderr: ${stderr}`);
});

根据您应使用的执行文件的文档类型:

child\u process.execFile(文件[,参数][,选项][,回调])

这对你有用

const { execFile } = require('child_process');
execFile('/home/nadhem/TradeFinance/Backend/SmartContract/approveLOC.sh', 
(err, stdout, stderr) => {
  if (err) {
    return;
  }

  // the *entire* stdout and stderr (buffered)
  console.log(`stdout: ${stdout}`);
  console.log(`stderr: ${stderr}`);
});

您可以发布它抛出的实际错误吗?或者您可以查看
shelljs
()