Reply to Re: exec() incomplete $output

Your name:

Reply:


Posted by Erwin Moller on 12/29/06 11:56

ajh wrote:

> 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:
>
>
> <?php
>
> 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
> unset($out);
> exec("echo " . $querystr . " | " . PROG . " -i $indexfile -d
> $crawldir -n $namesfile -p $rankfile -m $maxhits", $out);
> }
>
> ?>
>
> <html>
> <body bgcolor="#ffffff">
>
> <br>
> <br>
> <form method="get" action="<?php print $_SERVER['PHP_SELF']?>">
> <input name="query" type="text" size="50" maxlength="50">
> <input type="button" value="submit" />
> </form>
>
> <br>
> <br>
>
> <?php
> // show output
> foreach ($out as $val)
> {
> echo htmlentities($val)."<br/>";
> }
> ?>
>
> </body>
> </html>

Hi,

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:
1) Environment:
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
interest)
Some missing environmentvariable could maybe screw up the execution of your
program?

2) Catch the result again as you did halfheartedly ;-) in your first
posting.
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.

Regards,
Erwin Moller

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация