Popen usage Issues in PHP

Source: Internet
Author: User
I have the program path:/usr/src/myappmamou/apps/myapp
On the command line, after you start the program MyApp, you can enter a command to run the program such as: Send Arg1 arg2 arg3
This allows the program to run successfully

Now that you want to do this in PHP, you don't need to enter commands on the command line every time: Send Arg1 arg2 arg3 can do the same

PHP is as follows:
        $fixedcmd = "Send 123456063 10000 1111111";        $ph = "/usr/src/myappmamou/apps/myapp";        $rs = Popen (\ "$ph \" \ "$fixedcmd \", "R");p Close ($RS);

The operation does not reach the effect, ask everyone have any problem? Thank you so much


Reply to discussion (solution)

1, whether PHP is executed via command line or CGI, do/usr/src/myappmamou/apps/myapp permissions
2, "first start the program MyApp" is to say that the program started alone? Can you give a send arg1 arg2 arg3 relationship
3. Does the current path have to be in a certain position when executing the start MyApp?

1, whether PHP is executed via command line or CGI, do/usr/src/myappmamou/apps/myapp permissions
2, "first start the program MyApp" is to say that the program started alone? Can you give a send arg1 arg2 arg3 relationship
3. Does the current path have to be in a certain position when executing the start MyApp?

1, PHP is placed in Apache execution, with permissions
2, "first start the program MyApp after" refers to the command line to start the program, such as./myapp, and then into the program myapp>
Input commands such as send Arg1 arg2 arg3,send are commands the other three are parameters
3. If the current path must be in a certain position at the start of MyApp, it is only possible to run under the/usr/src/myappmamou/apps, it is necessary to make the system command, that is, enter the command MyApp at any location to start the program
consulted the

If I want to be able to execute the command in any place MyApp, is not as long as the $path to add the path of MyApp, so the system will know the path of MyApp, should be able to identify it, but I tried, invalid

$rs = Popen (\ "$ph \" \ "$fixedcmd \", "R");???
I have to write.
$rs = Popen ("$ph $fixedcmd", "R");
It

You're doing the test.

 Array ("Pipe", "R"),///stdin is a pipe, the child would read from 1 = = Array ("Pipe", "w"),//stdout is a pipe t Hat the child would write to 2 = = Array ("File", "/tmp/error-output.txt", "a")//stderr are a file to write to); $CWD =    '/usr/src/myappmamou/apps '; $process = Proc_open (' MyApps ', $descriptorspec, $pipes, $CWD); if (Is_resource ($process)) { $pipes now looks like this://0 = writeable handle connected to child stdin//1 = readable handle Conne CTED to stdout//any error output would be appended to/tmp/error-output.txt$fixedcmd= "Send 123456063 10000 11111    11 ";    Fwrite ($pipes [0], $fixedcmd);    Fclose ($pipes [0]);    Echo stream_get_contents ($pipes [1]);    Fclose ($pipes [1]); It is important so 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";}
  • 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.