shell_exec 返回不正确

发布于 2024-12-12 05:25:49 字数 462 浏览 3 评论 0原文

我试图找出我要迭代的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余厌 2024-12-19 05:25:49

使用 PHP 计算文件中的行数

<?php 
  $file = "somefile.txt"; 

  $lines = count(file($file)); 

  echo "There are $lines lines in $file"; 
?>

它甚至适用于以“DOS”行结尾的文件。

Count lines in a file using PHP

<?php 
  $file = "somefile.txt"; 

  $lines = count(file($file)); 

  echo "There are $lines lines in $file"; 
?>

It even works on files with "DOS" line endings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文