popen fails with "sh: <command>: not found"

Posted by smallmeans on Stack Overflow See other posts from Stack Overflow or by smallmeans
Published on 2010-04-27T00:15:59Z Indexed on 2010/04/27 0:43 UTC
Read the original article Hit count: 432

Filed under:
|
|
|

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 prompt (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

© Stack Overflow or respective owner

Related posts about php

Related posts about popen