cristalmolix Posted March 12, 2010 Share Posted March 12, 2010 Hello Guys I have a script in development to execute a .bat file on windows, the bat file calls ssh [email protected] test.dat which creates a file on the server, however shell access is not allowed on the server and the command line will output please contact admin to get shell access, i need to output this to the browser, my code so far is as follows. I understand how pipes work but need some guidance from someone whos done this before or similar. currently the browser outputs process returned 0 when i close the command line that it opens, i need the command line to close itself obviously and take any output from it. and also i need to give it the password, i know this is done through the pip but its kinda tricky. C:\test.bat ssh [email protected] test.dat zend framework controller public function indexAction() { $descriptorspec = array( 0 => array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the child will write to 2 => array("file", "/error-output.txt", "a") // stderr is a file to write to ); $cwd = '/tmp'; $env = array('some_option' => 'aeiou'); $process = proc_open('start c:\test.bat', $descriptorspec, $pipes); //sleep(1); if (is_resource($process)) { // $pipes now looks like this: // 0 => writeable handle connected to child stdin // 1 => readable handle connected to child stdout // Any error output will be appended to /tmp/error-output.txt fwrite($pipes[0], '<?php print_r($_ENV); ?>'); fclose($pipes[0]); echo stream_get_contents($pipes[1]); fclose($pipes[1]); // It is important that you close any pipes before calling // proc_close in order to avoid a deadlock $return_value = proc_close($process); echo "command returned $return_value\n"; } exit; } thanks for any help Link to comment https://forums.phpfreaks.com/topic/195037-proc_open-reading-the-error-or-return/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.