Jump to content

Recommended Posts

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.

 

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 );
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.