[英]how can I execute a script shell with node.js
我正在嘗試使用node.js執行腳本外殼。我正在使用子進程,但是當我執行.js文件時,腳本外殼不會被執行。 此功能有什么問題?
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_process.execFile(file[, args][, options][, callback])
這將為您工作。
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.