问题描述
我正在开发服务器应用程序,最近在测试服务器(Debian Squeeze)上遇到了这个奇怪的错误.
I'm developing a server application and I recently encountered this wierd error on a testing server (Debian Squeeze).
我传递给 popen 的每个可执行文件均会失败,并显示msg:
Every executable I pass to popen fails with a msg:
sh: sort: not found // happens to any command
无论我指向"type"返回的完整路径还是使其简短,都会发生这种情况.如前所述,这种情况仅在一个测试环境中发生,这增加了混乱,正在同一操作系统上运行,并且没有任何问题.
This happens regardless whether I point to the full path returned by "type" or keep it short .As mentioned earlier, this happens at only one testing environment, to add confusion, am running the same OS and had no problem whatsoever.
Popen显然是使用 sh 来执行命令的,但是如果我通过命令行(bash或sh)运行相同的命令,一切都会很好
Popen is apparently using sh to execute commands, but if I run the same command thru the command-line (bash or sh), everything's fine
预先感谢
(PS:甚至尝试过用Python os.popen钉住这个头抓痒器,它的确起作用!)
(PS: even tried Python os.popen just to nail this head scratcher, and it works!)
修改这是一个失败的简单调用:
Editthis is a simple call that fails:
$command="tail -10 myfile";
$handle = popen($command.' 2>&1','r');
if($handle){
while (!feof($handle)){
....//process buffer
}
}
返回:
sh: tail: not found
推荐答案
调用popen时,您的PATH可能配置不正确.我想这是一个PHP配置问题,但是您可以通过以下方式绕过它:
Probably your PATH is NOT configured properly, when calling popen. I guess this is a PHP configuration problem, but you can bypass it by:
- 运行
which tail
以确定尾部程序的完整路径. - 使用在1中找到的路径调用
popen
.
- Run
which tail
to determine the full path to the tail program. - Call
popen
with the path found in 1.
这篇关于popen失败,并显示"sh:< command> ;:未找到".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!