Reputation: 876
I have a piece of code as follows:
$process = proc_open(sprintf('node "%s"', $tmpfile), $desc, $pipes);
Which produces
sh: node: command not found
I tried to set $PATH
in httpd.conf
with SetEnv
, then echo it using getenv('PATH')
. The output actually contains the path to node.
I was able to pass the variable to proc_open
, but I'd like to avoid that because it's someone else's code.
Is there a way for me to give it the correct path?
I am running XAMPP 1.8.2 for Mac OS X.
Upvotes: 2
Views: 2637
Reputation: 411
proc_open lets you pass environment variable into it. This is probably the easiest to get node if the path of your PHP spawned process.
$env = array(
'PATH' => '/usr/local/bin' //Path to node bin dir
);
$process = proc_open($command, $descriptorspec, $pipes, __DIR__, $env);
Upvotes: 4
Reputation: 5503
After the $pipes you can assign the CWD. You should pass it here. In terms of setting the cwd with the php.ini file, I don't think this is possible.
You should be able to do the following:
$process = proc_open(sprintf('node "%s"', $tmpfile), $desc, $pipes, __DIR__);
Providing the "node" executable is in the same directory. Alternatively you could move "node" to
echo getcwd();
Although this is a bit messy usually.
Edit: You should also be able to get away with using an alias or symlink to the cwd
Upvotes: 1