Reputation: 103
This question is related to Nodejs Child Process with Unix Executable.
However I could not find a good solution and thanks to my reputation points, I am unable to post a comment there.
To explain my problem, I have some of my own executables which I need to execute from node.js. The path for these executables is already set in the PATH variable. Hence, I can run my executables without any path-prefix from Terminal.
Inspite of that, node.js receives process.env.PATH set to following value:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
I tried appending the path to it before spawning the process:
process.env.PATH = process.env.PATH + ":<path_to_my_executables>"
but the process exits with 127 Shell code which is "command not found" if I correctly remember.
Any ideas?
Thank you in advance!
Upvotes: 3
Views: 1012
Reputation: 103
Okay, I got it work using a shell script. Definitely there must be a better solution to this.
I exported the required paths to my executable (and its dependencies) in the shell script first and then started execution. Hence the shell script structure is something like:
export JAVA_HOME=<java_path>
export EXECUTABLES_HOME=<executables_path>
export PATH="$PATH:$JAVA_HOME/bin:$EXECUTABLES_HOME"
<execute_required_executable> <arguments>
If someone has a better solution, please do let me know!
Upvotes: 1