如何在 bash 脚本中超时? [复制]

Posted

技术标签:

【中文标题】如何在 bash 脚本中超时? [复制]【英文标题】:How to timeout within a bash script? [duplicate] 【发布时间】:2012-10-18 09:37:25 【问题描述】:

可能重复:Timeout a command in bash without unnecessary delay

这就是我想要做的-

for test in `ls Tests`; do

for file in `ls FileFolder`; do

output=`python devcap $test $file`

echo $test $file $output >>result.txt

done

done

如果 $output 花费的时间超过 5 秒并移动到下一个 $file,我该如何超时?

我也可以将 stderr 重定向到 result.txt 吗?

【问题讨论】:

***.com/questions/687948/… 【参考方案1】:

试试这个:

for test in `ls Tests`; do

for file in `ls FileFolder`; do

output=`python devcap $test $file`

sleep 5

echo $test $file $output >>result.txt

done

done

【讨论】:

我试过了。它不工作。代码只是挂断了shell,并没有前进。 您是否尝试在代码中添加 sleep 5?顺便说一句,我更新了我的答案

以上是关于如何在 bash 脚本中超时? [复制]的主要内容,如果未能解决你的问题,请参考以下文章