Fread cannot read the popen value, but runs normally in the command line.

Source: Internet
Author: User
Fread cannot read the popen value, but runs normally in the command line. fread cannot read the popen value.

$output = '';$pipe = popen($somecommand, 'r');while(!feof($pipe)){ $output .= fread($pipe, 1024);}


Execute $ somecommand in the command line to display the code normally, but the value cannot be obtained when the above code can be run.


Reply to discussion (solution)

You need to confirm:
1. $ somecommand is a process rather than a thread
2. $ somecommand is written to the standard output.

This type of application can be used in the Test environment. If this type of function is disabled in the official environment for security reasons, isn't it enough?

You need to confirm:
1. $ somecommand is a process rather than a thread
2. $ somecommand is written to the standard output.

This type of application can be used in the Test environment. If this type of function is disabled in the official environment for security reasons, isn't it enough?
I haven't come to CSDN for a long time. I am nagging the moderator to answer this question myself. thank you first. I have also considered the problem of security and efficiency and want to switch to socket for calling. I would like to ask again: in PHP, if there is any better solution for similar applications, so as to get the call value? Thank you.

$output = '';$pipe = popen($somecommand, 'r');while(!feof($pipe)){ $output .= fread($pipe, 1024);}


Execute $ somecommand in the command line to display the code normally, but the value cannot be obtained when the above code can be run.
You command to add this "2> & 1", I see here: http://blog.csdn.net/kangear/article/details/9141481
The command I used is dd, which is the same as your problem. it is okay to add that.

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.