Re: exec() incomplete $output
> Thanks for your suggestions Erwin. I've turned on all the error
> messages and done some minor debugging. Nothing that related to the
> output though. The underlying program is a basic search engine - you
> are right about the html output so I made that htmlentities change but
> it didn't make a difference.
> Here is the code:
> define("PROG", "/blah/bling/query");
> $crawl = "courses";
> $indexfile = "$crawl.csv";
> $crawldir = "$crawl";
> $namesfile = "$crawl.names";
> $rankfile = "$crawl.rank";
> $maxhits = 10;
> $querystr = escapeshellarg($_GET['query']);
> // Check if querystr is present
> if ($querystr!=NULL)
> // Run the query
> exec("echo " . $querystr . " | " . PROG . " -i $indexfile -d
> $crawldir -n $namesfile -p $rankfile -m $maxhits", $out);
> <body bgcolor="#ffffff">
> <form method="get" action="<?php print $_SERVER['PHP_SELF']?>">
> <input name="query" type="text" size="50" maxlength="50">
> <input type="button" value="submit" />
> // show output
> foreach ($out as $val)
> echo htmlentities($val)."<br/>";
Well, that is strange indeed.
As far as I can see your approach works, and I do not see any reason why a
call to the program works from a shell, but not via PHP.
2 things you can try:
Before executing the command, create it in a string and echo that.
Copy/paste it into a shell, WITH the same environment as your PHP script,
and see if that works as expected. (use phpinfo() to find settings of
Some missing environmentvariable could maybe screw up the execution of your
2) Catch the result again as you did halfheartedly ;-) in your first
Do add the $result again as third argument to the exec(), and see if that
contains anything of interest after you called exec.
It could possibly contain some error.