Reputation: 23
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 . 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}`);
});
Upvotes: 0
Views: 461
Reputation: 2913
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}`);
});
Upvotes: 1