Home > Software design >  Node.js child_process exec command scope
Node.js child_process exec command scope

Time:12-05

I have this string I need to execute on MacOS shell: solana --help It runs fine as expected in the macOS terminal, even if I cd into my project directory.

The said application is on my global PATH too.

I have the following code opened in my vscode project:

const util = require('util');
const exec = util.promisify(require('child_process').exec);

(async () => {
    const { stdout, stderr } = await exec('solana --help');
    console.log('stdout:', stdout);
    console.log('stderr:', stderr);
})();

Instead of showing expected output, the program errors out and shows the following error:

https://i.stack.imgur.com/fseXV.png

CodePudding user response:

You need to type whereis solana in the command line to find the full path to that executable, then replace that in your code, i.e:

 const { stdout, stderr } = await exec('full_path_to_solana --help');

Then show us the result.

  • Related