0

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}`);
});
2
  • Can you post the actual error it's throwing? Commented Aug 3, 2018 at 11:24
  • Alternatively you can check out shelljs (npmjs.com/package/shelljs) Commented Aug 3, 2018 at 11:56

1 Answer 1

1

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}`);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.