shell_exec 返回不正确
我试图找出我要迭代的 CSV 中存在多少行,以便监控进度。
从命令行,这给出了正确的值:
cat /path/to/CA_MA.csv | perl -p -i -e "s/^M/\n/g" | wc -l
但是,使用 shell_exec()
,我什么也没得到:
trim( shell_exec( "cat /path/to/CA_MA.csv | perl -p -i -e 's/^M/\n/g' | wc -l" ) )
我已经尝试了 STDOUT 和 STDERR (... 2>&1
)。我已经从交互式控制台(php -a
)的脚本中尝试了这一点。
I'm trying to figure out how many lines exist in a CSV I'm about to iterate over so I can monitor progress.
From the command line, this gives the correct value:
cat /path/to/CA_MA.csv | perl -p -i -e "s/^M/\n/g" | wc -l
However, using shell_exec()
, I get nothing back:
trim( shell_exec( "cat /path/to/CA_MA.csv | perl -p -i -e 's/^M/\n/g' | wc -l" ) )
I've tried both STDOUT and STDERR (... 2>&1
). and I've tried this from my script from the interactive console (php -a
).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 PHP 计算文件中的行数
它甚至适用于以“DOS”行结尾的文件。
Count lines in a file using PHP
It even works on files with "DOS" line endings.