greatwhitepine Posted May 5, 2007 Share Posted May 5, 2007 Hi, I'm trying to have a php cli script execute and wait for the termination of vi using proc_open however vi never opens. Here is the code... $arr_pipes = array( ); $str_command = 'vi /etc/passwd'; $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","/dev/null", "w") // stderr is a file to write to ); $process = proc_open($str_command, $descriptorspec, $pipes); 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 fclose($pipes[0]); 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); } Anyone have any suggestions? I'm using ssh (Putty) and my shell is csh. Quote Link to comment https://forums.phpfreaks.com/topic/50080-solved-cli-using-proc-open-to-run-an-interactive-command/ Share on other sites More sharing options...
greatwhitepine Posted May 5, 2007 Author Share Posted May 5, 2007 bump... Quote Link to comment https://forums.phpfreaks.com/topic/50080-solved-cli-using-proc-open-to-run-an-interactive-command/#findComment-246273 Share on other sites More sharing options...
greatwhitepine Posted May 8, 2007 Author Share Posted May 8, 2007 bump (last time). Quote Link to comment https://forums.phpfreaks.com/topic/50080-solved-cli-using-proc-open-to-run-an-interactive-command/#findComment-248365 Share on other sites More sharing options...
greatwhitepine Posted May 8, 2007 Author Share Posted May 8, 2007 Stumbled upon the answer... file and "php: ... " must be used for both descriptor 0 and 1. $arr_pipes = array( ); $str_command = 'vi /etc/passwd'; $descriptorspec = array( 0 => array( "file", "php://stdin", "r" ), // stdin is a file that the child will read from 1 => array( "file", "php://stdout", "w" ), // stdout is a file that the child will write to 2 => array( "file", "/dev/null", "w" ) // stderr is a file that the child will write to ); $process = @proc_open( $str_command, $descriptorspec, $arr_pipes ); if ( is_resource( $process ) ) { $return_value = proc_close( $process ); } Quote Link to comment https://forums.phpfreaks.com/topic/50080-solved-cli-using-proc-open-to-run-an-interactive-command/#findComment-248457 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.