dounie0889 2009-10-12 05:03
浏览 57
已采纳

proc_open工作目录

I have a PHP script at the following location C:\wamp\www\tcl\bin\

I am accessing the same through a browser (http://localhost/tcl/bin/xxx.php

In the PHP script . I am doing a proc_open

$app = 'C:/wamp/www/tcl/bin/tclsh84.exe';
$process = proc_open($app, $descriptorspec, $pipes);

if i give the full path it works , but if I just give tclsh84.exe it does not work . Although the PHP manual states if you don't give 4th parameter of proc_open (CWD) it takes the directory of the currently executing process.

Can someone guide me as I can't hardcode the tcl executable path as this needs to work both in windows and linux .

Regards, Mithun

  • 写回答

2条回答 默认 最新

  • dongyuan1160 2009-10-12 05:45
    关注

    You say it works if you use the full path to tclsh84.exe. So, a solution might be to find out that full path and use it in your call to proc_open.


    If you know your tclsh84.exe is in the directory in which your PHP script is, you could use something based on dirname and __FILE__ ; a bit like this, I suppose :

    $dir = dirname(__FILE__);
    var_dump($dir);   // directory in which the current PHP script is in
    
    $path = $dir . DIRECTORY_SEPARATOR . 'tclsh84.exe';
    var_dump($path);
    

    Considering the PHP script I am using is /home/squale/developpement/tests/temp/temp.php, I would get :

    string '/home/squale/developpement/tests/temp' (length=37)
    string '/home/squale/developpement/tests/temp/tclsh84.exe' (length=49)
    

    And, if needed, you can use '..' to go up in the directories tree, and, then use directories names to go down.


    Another solution might be to make sure that the program you are trying to execute is in your PATH environment variables -- but if it's a program that's used only by your application, it doesn't make much sense to modify your PATH, I guess...

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

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。