Problems related to proc_open + fwrite application in php

Source: Internet
Author: User
In php, proc_open + fwrite application problems I want to use proc_open in php to call a c ++-written exe program. because it requires the input of parameters, I use fwrite to write data to the terminal, the php code is as follows: PHPcode & lt ;? Php $ descriptorspec = array (0 = & gt; array (& quot; proc_open + fwrite application problems in php
I want to use proc_open in php to call an exe program written in c ++. because the input parameters are required, I use fwrite to write the program to the terminal. The php code is as follows:
PHP code
  
   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);$process = proc_open("d:\\64test.exe", $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        fwrite($pipes[0], "q");    fclose($pipes[0]);    while (!feof($pipes[1]))     {        $result = fgets($pipes[1], 1024);        echo "r:$result
"; } 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
";}?>

The c ++ code is as follows:
C/C ++ code
  #include 
  
   using namespace std;int main(int argc,char *argv[]){    char buf[1024]={0};    /*fgets(buf,sizeof(buf),stdin);*/    while(buf[0]!='q')    {        std::cin>>buf;        std::cout<
   
  

The above c ++ is a simplified code
(1) The problem is that the code in my c ++ is a while loop that requires continuous input.
Ask how to write data in php. Currently, only fwrite ($ pipes [0], "q") can be used in php, but not in php.
(2) the above program can be printed normally.
R: q
Command returned-3
I always print the following in another very complex cpp program:
R:
Command returned-1073741515
Later, I commented out other codes in main and directly copied the simple c ++ code above to my project. The result is still above. this is my biggest question, has anyone ever met?

Thank you!

------ Solution --------------------
Fwrite ($ pipes [0], "cmd1 \ ncmd2 \ ncmd3 \ nq"); try it
------ Solution --------------------
What do you mean?
It allows you to assemble the output data into strings and then output the data at one time.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.