doutou3725 2013-07-24 09: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 10: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条)

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试