小编scr*_*gar的帖子

如何在Perl中实时读取外部命令的输出?

我运行了一些bash脚本,但它们可能需要几个小时才能完成,在此期间它们会发出下载速度,ETA和类似信息.我需要在perl中捕获这些信息,但是我遇到了一个问题,我无法逐行读取输出(除非我遗漏了一些东西).

任何帮助解决这个问题?

编辑:更好地解释这个我正在运行几个bash脚本,我希望使用gtk与perl生成方便的进度条.目前我为每个我希望运行的bash脚本运行2个线程,一个用于更新图形信息的主线程.它看起来像这样(尽可能减少):

  my $command1 = threads->create(\&runCmd, './bash1', \@out1);
  my $controll1 = threads->create(\&monitor, $command1, \@out1);
  my $command1 = threads->create(\&runCmd, 'bash2', \@out2);
  my $controll2 = threads->create(\&monitor, $command2, \@out2);

  sub runCmd{
     my $cmd = shift;
     my @bso = shift;
     @bso = `$cmd`
  }
  sub monitor{
     my $thrd = shift;
     my @bso = shift;
     my $line;
     while($thrd->is_running()){
       while($line = shift(@bso)){
         ## I check the line and do things with it here
       }
       ## update anything the script doesn't tell me here.
       sleep 1;# …
Run Code Online (Sandbox Code Playgroud)

bash perl stdin

5
推荐指数
1
解决办法
3606
查看次数

如何在我的crontab中使用查询字符串?

我需要在我的crontab中有一个查询字符串,但它不起作用.有人可以告诉我怎么做到这一点?

谢谢

php linux

1
推荐指数
2
解决办法
3917
查看次数

标签 统计

bash ×1

linux ×1

perl ×1

php ×1

stdin ×1