[英]how can I execute a script shell with node.js
I am trying to execute a script shell with node.js .I am Using a child process but when I execute the .js file the script shell is not bee executed . 我正在尝试使用node.js执行脚本外壳。我正在使用子进程,但是当我执行.js文件时,脚本外壳不会被执行。 What's wrong with this function? 此功能有什么问题?
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}`);
});
Based of documentation for execution file you should use: 基于执行文件的文档,您应该使用:
child_process.execFile(file[, args][, options][, callback])
This would work for you. 这将为您工作。
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}`);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.