如何拖尾 adb logcat 的输出并在每个新行执行命令

How to tail output from adb logcat and execute a command each new line

我很可能会 this post 但我不想从文件中读取 "subscribe" 到 adb logcat 的输出,每次换行时记录我将运行这一行的一些代码。

我尝试了这些代码,但 none 有效

tail -f $(adb logcat) | while read; do 
    echo $read;
    processLine $read;
done

adb logcat >> logcat.txt &
tail -f logcat.txt | while read; do 
    echo $read;
    processLine $read;
done

最简单的方法是什么?提前致谢

以下两种解决方案应该有效。我通常更喜欢第二种形式,因为当前进程中的 wile 循环是 运行,所以我可以使用局部变量。第一种形式 运行 是子进程中的 while 循环。

子进程中的 While 循环:

#!/bin/bash

adb logcat |
while read -r line; do
  echo "${line}"
  processLine "${line}"
done

当前进程中的 While 循环:

#!/bin/bash

while read -r line; do
  echo "${line}"
  processLine "${line}"
done < <(adb logcat)