A certain shell result of php exec() is wrong. The reason is that grep in php can only process text streams, not binary streams_PHP Tutorial

WBOY
Release: 2016-07-14 10:09:27
Original
856 people have browsed it

cat aa.txt | grep 'startup' |wc-l

There is no problem when testing under the linux command line. But there is a problem with php's exec, which is very strange.
Result error:
The error message is as follows: cat: write error: Broken pipe
After a lot of effort and checking a lot of information, I finally solved it.
Add the -a option to grep and it will be ok
The grep -a option means: Process a binary file as if it were text; this is equivalent to the --binary-files=text option
It should be that the content of the cat file contains a binary stream, causing grep to not recognize it

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477649.htmlTechArticlecat aa.txt | grep startup |wc-l There is no problem when testing under the linux command line. But there is a problem with php's exec, which is very strange. The result is an error: The error message is as follows: cat: write erro...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!