user2554585
user2554585

Reputation: 3669

Node-Webkit Child Process Exec

I want to execute a homebrew command for example

brew list

I followed the documentation and executed it like this:

child = exec('brew', function (error, stdout, stderr) {
 console.log(stdout);
 console.log(stderr);
});

I am getting a command not found error, and realized that if I do /usr/local/bin/brew as the command it works. However simply using 'brew' should work as well since I can run 'brew' from the command line just as such.

Why is this the case and what does it take to make 'brew' run as a child process in node? I have a feeling part of the issue because the command on node-webkit seems to execute from bin/sh.

Thanks

Upvotes: 1

Views: 1031

Answers (1)

OldGeeksGuide
OldGeeksGuide

Reputation: 2918

It may depend on how you're starting node-webkit and how you're setting your PATH. When I start from the command line, it inherits the environment variables from my command-line environment, including PATH. If I start by double clicking in a gui, it inherits from the system (presumably /etc/paths), and any additions I make in my .bashrc/.bash_profile have no effect.

Also, I'm no security expert, but my understanding of best practices would include using an absolute path to the executable you're running, so it's harder to spoof by setting an environment variable. By that measure, you're better off using the full path to brew anyway.

Upvotes: 1

Related Questions