gpt4 book ai didi

bash - 处理意外的 bash 命令输出

转载 作者:行者123 更新时间:2023-12-03 08:00:24 25 4
gpt4 key购买 nike

我正在尝试处理 for 循环中命令的意外输出。我正在使用专有的解压缩实用程序 ( mfunzip ),但是当实用程序遇到损坏的文件时,它开始回显无休止的“InputBit 中的 fatal error !”信息。

我正在 try catch 输出并继续循环到下一个文件。

for FILE in $(ls); do
if [ -d "$FILE" ]; then
...
...
# without command output, it runs indefinitely
output=$(mfunzip $currentfile $extractdir)

# it never reaches here
echo $output
if [[ $output = *Fatal* ]]; then
continue
fi
fi
done

但是它似乎没有工作,因为它在 处阻塞输出=$(mfunzip ... ) ...我会假设它无休止地输出到 $输出 .另一个问题似乎是“ fatal error ”可能不会立即出现,而是在尝试 的过程中途出现。 mfunzip 文件。

有没有更好的方法来处理这种类型的输出?

最佳答案

要“处理命令的(意外或预期的)输出”,您应该使用:http://en.wikipedia.org/wiki/Expect ,这是专门为这种事情设计的。

关于bash - 处理意外的 bash 命令输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22146766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com