Re: passthru() passing variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, June 15, 2005 5:36 pm, Chris Herold said:
> I have been told that in order to pass variables via passthru() to
> another script (in my case, a perl script) one can do the following ...
>
> passthru("home/test.cgi $var")
>
> and that $var will then be passed through to the cgi.
>
> I have tried this and failed.
>
> Is this the proper format or is there something that I am missing.

You may want to use exec first, so you can more easily capture the error
output and error codes.

exec("home/test.cgi $var", $output, $error);
if ($error){
  //You should probably use error_log here in your real code...
  //ASSUME this is going to break some day, for whatever reason.
  //You'll need it logged unless you like dealing with error reports like:
  //"Hey, the website broke yesterday."
  echo "OS Error:  $error<br />\n";
  echo implode("<br />", $output);
  exit;
}
echo $output;

Meanwhile, odds are *REALLY* good that you're not even calling the
test.cgi script because you haven't provide a path that PHP can use.

home/test.cgi would be assuming that home was in the same directory as
your PHP script, and even that is kinda iffy depending on where you do
this from the webserver or CLI...

I would recommend using FULL PATH to *everything* in exec (and passthru)

/full/path/to/home/test.cgi /full/path/to/any/args.txt

Also be sure to use the escapeshellargs function to make your $var data
kosher if it comes from the outside world.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux