Page 1 of 1

Passthru not working

Posted: Mon Jun 10, 2002 11:35 pm
by Paul Oertel
I am trying to use the passthru command to run an executable.

<?php

@ $p1= $HTTP_POST_VARS["param1"];
@ $p2= $_POST["param2"];

trim($computer);
trim($sid);

if (!$p1|| !$p2)
{
echo "You have not entered the correct arguments. Please go back and try again.";
exit;
}

$command = "c:\program files\webserver\cgi-bin\myexec.exe \\\\".$computer." ".$sid;

echo $command;

passthru($command);

?>

</body>
</html>

I don't think that I have coded it wrong because I get no errors and I echo $command returns the proper value. If I substitute my command for something like "time /t" it works just fine.

I thought that safe mode might have something to do with it so I tried it with safe mode both on and off. It didn't make any difference. I have also set the safe_mode_exec_dir directive to the same path I have used in the code.

I read somewhere that it might be a permissions problem but right now the permissions to the directory and executable are set to full control for everyone.

Could someone help me pass this obstacle? I would greatly appreciate it.

By the way, I'm not to keen on turning safe mode off.
Paul

Posted: Mon Jun 10, 2002 11:36 pm
by Paul Oertel
one small correction the variables in the $command variable should be $p1 and $p2. A mistype on my part.

Posted: Tue Jun 11, 2002 1:10 am
by volka
first of all: what is your problem?
The documention does not mention that passthru() will only display standard
output and not standard error.

If you are running a script you can pipe the STDERR to STDOUT by doing

exec 2>&1

Eg. the script below will actually print something with the passthru()
function...

#!/bin/sh
exec 2>&1
ulimit -t 60
cat nosuchfile.txt
it's from the user contributed notes for passthru
EDIT:
$command = "c:\program files\....;
ahh, win32. It does not know exec 2>&1 or ulimit but <command> 2>&1 works

Posted: Tue Jun 11, 2002 8:02 pm
by Paul Oertel
Volka,

After all my explaination I forget to say what the problem was. I not getting any output returned to the web page. If I include a return value and then echo the value to the page it displays a 1.

passthru($command,$result);
echo $result;


If I'm not mistaken this means that the executable exited without out any errors.

Paul