【发布时间】:2012-02-22 15:38:18
【问题描述】:
我想在创建 shell 的那一刻处理每个标准输出行。我想获取test.sh 的输出(一个漫长的过程)。我目前的做法是这样的:
./test.sh >tmp.txt &
PID=$!
tail -f tmp.txt | while read line; do
echo $line
ps ${PID} > /dev/null
if [ $? -ne 0 ]; then
echo "exiting.."
fi
done;
但不幸的是,这将打印“exiting”然后等待,因为 tail -f 仍在运行。我尝试了break 和exit
我在 FreeBSD 上运行它,所以我不能使用某些 linux tails 的 --pid= 选项。
我可以使用ps 和grep 来获取尾巴的pid 并杀死它,但这对我来说似乎很丑。
有什么提示吗?
【问题讨论】: