Passthru not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Paul Oertel
Forum Newbie
Posts: 18
Joined: Fri May 31, 2002 3:44 am
Location: Japan

Passthru not working

Post 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
Paul Oertel
Forum Newbie
Posts: 18
Joined: Fri May 31, 2002 3:44 am
Location: Japan

Post by Paul Oertel »

one small correction the variables in the $command variable should be $p1 and $p2. A mistype on my part.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
Paul Oertel
Forum Newbie
Posts: 18
Joined: Fri May 31, 2002 3:44 am
Location: Japan

Post 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
Post Reply