problem executing command

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
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

problem executing command

Post by yacahuma »

I am trying to connect remotely to a machine an run a little script. Then get the output in php.
The script runs find in the command line. Now when I try running it using php, I get the following error

[text]
Array
(
[stdout] =>
[stderr] => 'c:/Windows/System32/plink.exe' is not recognized as an internal or external command,
operable program or batch file.

[return] => 1
)

[/text]

I am using a little script that I found on php.net

Code: Select all

 function my_exec($cmd, $input='')
         {$proc=proc_open($cmd, array(0=>array('pipe', 'r'), 1=>array('pipe', 'w'), 2=>array('pipe', 'w')), $pipes);
          fwrite($pipes[0], $input);fclose($pipes[0]);
          $stdout=stream_get_contents($pipes[1]);fclose($pipes[1]);
          $stderr=stream_get_contents($pipes[2]);fclose($pipes[2]);
          $rtn=proc_close($proc);
          return array('stdout'=>$stdout,
                       'stderr'=>$stderr,
                       'return'=>$rtn
                      );
         }
The plink is in windows\system32 so any program should be able to find it, right? In any case I gave it the whole path and still have the same problem.

My script

Code: Select all

        $cmd ="c:/Windows/System32/plink.exe -ssh -pw password user@host \"/path/findlog.sh {$phone}\"";
        echo $cmd;
        var_dump(my_exec($cmd));

Thank you for any help
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: problem executing command

Post by AbraCadaver »

Not sure, try:

Code: Select all

$cmd = "c:\\Windows\\System32\\plink.exe -ssh -pw password user@host \"/path/findlog.sh {$phone}\"";
exec($cmd, $output);
print_r($output);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: problem executing command

Post by yacahuma »

Thank you. Now it worked with shell_exec. WEIRD!!!
Post Reply