doutou3725 2013-07-24 01:31
浏览 38
已采纳

如何为proc_open设置正确的PATH

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.

  • 写回答

2条回答 默认 最新

  • duanqianruan8448 2013-07-24 02:51
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部