Maison  >  Article  >  développement back-end  >  php exec()某个shell结果出错,原因是php中的 grep只能处理文本流,二进制流不行_PHP教程

php exec()某个shell结果出错,原因是php中的 grep只能处理文本流,二进制流不行_PHP教程

WBOY
WBOYoriginal
2016-07-14 10:09:27858parcourir

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

在linux命令行下测试没有问题。但是在php的exec的就出现问题了,很奇怪。
结果报错:
报错提示如下:cat: write error: Broken pipe
 
 
废了好大劲,查了好多资料,终于解决。
grep的选项增加-a选项就ok了
 
grep -a选项的意思是:Process a binary file as if it were text; this is equivalent to the --binary-files=text option
 
应该是cat的这个文件内容有二进制流,导致grep不识别 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/477649.htmlTechArticlecat aa.txt | grep startup |wc-l 在linux命令行下测试没有问题。但是在php的exec的就出现问题了,很奇怪。 结果报错: 报错提示如下:cat: write erro...
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn