how to get output of proc_open()

后端 未结 2 1036
迷失自我
迷失自我 2021-01-01 19:51

I\'ve tried to get output from proc_open method in php, but, when I print it, I got empty.

$descriptorspec = array(
    0 => array(\"pipe\", \"r\"),
         


        
2条回答
  •  天涯浪人
    2021-01-01 20:28

    this is another example with proc_open(). I am using Win32 ping.exe command in this example. CMIIW

    set_time_limit(1800);
    ob_implicit_flush(true);
    
    $exe_command = 'C:\\Windows\\System32\\ping.exe -t google.com';
    
    $descriptorspec = array(
        0 => array("pipe", "r"),  // stdin
        1 => array("pipe", "w"),  // stdout -> we use this
        2 => array("pipe", "w")   // stderr 
    );
    
    $process = proc_open($exe_command, $descriptorspec, $pipes);
    
    if (is_resource($process))
    {
    
        while( ! feof($pipes[1]))
        {
            $return_message = fgets($pipes[1], 1024);
            if (strlen($return_message) == 0) break;
    
            echo $return_message.'
    '; ob_flush(); flush(); } }

    Hope this helps =)

提交回复
热议问题