如果我使用 PHP 的 popen 命令执行脚本,是否在 PHP 的当前目录的上下文中执行它?
目前我正在做一些事情
popen(' cd PATH; CMD');
但我可以这样做吗
chdir ('PATH');
popen('CMD');
这取决于它运行的上下文。
当我从命令行使用 popen() 时,它在我运行它的 WD 中运行。
[ghoti@pc ~]$ php -r '$h=popen("pwd","r"); print fread($h, 80);'
/home/ghoti
[ghoti@pc ~]$ php -r 'chdir("/tmp"); $h=popen("pwd","r"); print fread($h, 80);'
/tmp
是的,它确实。我刚刚在 Windows 7 上使用 Apache PHP/5.3.2 对其进行了测试。