Use of popen in php

Source: Internet
Author: User
Php popen usage problems I have the program path:/usr/src/myappMamou/apps/myapp
In the command line, after starting the program myapp, you can enter the command to run the program, for example, send arg1 arg2 arg3
In this way, the program can run successfully.

To complete the above functions in PHP, you do not need to enter the command: send arg1 arg2 arg3 in the command line each time to achieve the same effect.

PHP is as follows:
        $fixedcmd="send 123456063 10000 1111111";        $ph="/usr/src/myappMamou/apps/myapp";        $rs = popen(\"$ph\" \"$fixedcmd\", "r" );pclose($rs);

If the running fails, do you have any questions? Thank you very much.


Reply to discussion (solution)

1. whether php is executed through command line or cgi, and whether to execute/usr/src/myappMamou/apps/myapp permissions
2. "after the program myapp is started first", does this program start independently? Can we provide a relationship between send arg1 arg2 arg3?
3. do the current path must be in a certain position when the myapp is started?

1. whether php is executed through command line or cgi, and whether to execute/usr/src/myappMamou/apps/myapp permissions
2. "after the program myapp is started first", does this program start independently? Can we provide a relationship between send arg1 arg2 arg3?
3. do the current path must be in a certain position when the myapp is started?

1. php is executed in apache and has permissions.
2. "start the program myapp first" means to start the program in the command line, such as./myapp, and then enter myapp>
The input command is as follows: send arg1 arg2 arg3; send is the command. The other three are parameters.
3. when the myapp is started, does the current path have to be in a certain position and can only be run under/usr/src/myappMamou/apps? is it necessary to make it like a system command, you can run the myapp command at any location to start the program.
Consulted

If I want to execute the command myapp anywhere, do I just need to add the PATH of myapp to $ PATH? in this way, the system will know the PATH of myapp and should be able to recognize it, but I tried it. it is invalid.

$ Rs = popen (\ "$ ph \" \ "$ fixedcmd \", "r ");???
Why do I have to write?
$ Rs = popen ("$ ph $ fixedcmd", "r ");
Right

How do you perform the test?

  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", "/tmp/error-output.txt", "a") // stderr is 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 connected to child stdout    // Any error output will be appended to /tmp/error-output.txt$fixedcmd="send 123456063 10000 1111111";    fwrite($pipes[0], $fixedcmd);    fclose($pipes[0]);    echo stream_get_contents($pipes[1]);    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\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.