tags:

views:

256

answers:

1

I'm developing a server application and I recently encountered this wierd error on a testing server (Debian Squeeze).

Every executable I pass to popen fails with a msg:

sh: sort: not found // happens to any command

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 is apparently using sh to execute commands, but if I run the same command thru the command-line (bash or sh), everything's fine

Thanks in advance

(PS: even tried Python os.popen just to nail this head scratcher, and it works!)

Edit this is a simple call that fails:

$command="tail -10 myfile";
$handle = popen($command.' 2>&1','r');
if($handle){
  while (!feof($handle)){
  ....//process buffer
  }
}

returns:

sh: tail: not found
+1  A: 

Probably your PATH is NOT configured properly, when calling popen. I guess this is a PHP configuration problem, but you can bypass it by:

  1. Run which tail to determine the full path to the tail program.
  2. Call popen with the path found in 1.
Spidey
This is the first thing I tried. The "type" command is similar to "which" on Debian and gives the full path.. but to no avail.. popen still persists on "not found", which is quite perplexing at this point..
smallmeans