Page 1 of 1

problem executing command

Posted: Tue Jul 20, 2010 1:26 pm
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

Re: problem executing command

Posted: Tue Jul 20, 2010 1:36 pm
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);

Re: problem executing command

Posted: Tue Jul 20, 2010 2:21 pm
by yacahuma
Thank you. Now it worked with shell_exec. WEIRD!!!