【问题标题】:How to edit output of "tail"?如何编辑“尾巴”的输出?
【发布时间】:2019-06-04 21:21:12
【问题描述】:

我正在尝试为MakeMKV 创建一个网络进度条。

run # tail -f /disc_progress

我得到一个文件的结果:

PRGV: 0,0,65536 <= 0% (65536 goal = 100%)
from 0%
PRGV: 716,0,65536
,
PRGV: 13281,13281,65536
,
PRGV: 65042,65041,65536
until 100%
PRGV: 65536,65536,65536 <= 100%

65536 最后是100%,所以我可以开始一些事情了。 理想情况下,我想支付倒数第二个, 例如在PRGV: 65042,65041,65536

Var1 = 65042 and Var2 = 65041

如何切断开头的“PRGV:”? 我如何在最后削减65041,65536,这对我来说是重要的变量 0% 和中间的数字(逗号之间 (65041))。

那应该在 php 变量中:

echo $Disc_Progress=shell_exec("sudo tail -f / disc_progress");

链接到GitHub FFmpegUI.

【问题讨论】:

  • 欢迎来到 Stack Overflow。请阅读How to create a Minimal, Reproducible Example 和/或使用“引导模式”提问。
  • 您不能在shell_exec() 中使用tail -f,因为它永远不会退出,并且shell_exec() 在命令完成之前不会返回。
  • This is for a new Linux server, shell, php 在该输出中来自哪里?

标签: php bash shell


【解决方案1】:

您可以将tail -f 的输出通过管道传输到一个命令,该命令将其输入复制到其输出,直到它到达100% 行,然后退出。

$Disc_Progress=shell_exec("sudo tail -f /disc_progress | sed '/100%/q'");

您想要的行将是$Disc_Progress 中倒数第二行。

【讨论】:

    【解决方案2】:

    我正在寻找那个:

    $get_progress_value=shell_exec("tail -1  /disc_progress");
    $Progress_Array=preg_split('/:|,/',$get_progress_value);
    
        echo "<pre>";
        print_r($Progress_Array);
        echo "</pre>";  
    

    输出:

    Array
    (
        [0] => PRGV
        [1] => 120 
        [2] => 536
        [3] => 65536
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-17
      • 1970-01-01
      • 2015-09-10
      相关资源
      最近更新 更多