bash – 命令`timeout`不适用于Scala – 为什么?

建立:
Ubuntu 12.04,32位; Scala 2.9.1; Java 1.6.0_24

描述:

在bash命令行上,命令/usr/bin/timeout 10 scala -version工作正常,在bash脚本中执行时会卡住.

在命令行执行(持续时间<1秒):

user@ubuntu:~$/usr/bin/timeout 10 scala -version
Scala code runner version 2.9.1 -- copyright 2002-2011,LAMP/EPFL
user@ubuntu:~$echo $?
1

放入bash脚本的命令卡住了:

testScript.sh:

#!/bin/bash
/usr/bin/timeout 10 scala -version
echo "finished with $?"

执行testScript.sh(持续时间10秒):

user@ubuntu:~/scripts$./testScript.sh
Scala code runner version 2.9.1 -- copyright 2002-2011,LAMP/EPFL
finished with 124
user@ubuntu:~/scripts$

注意:问题不会出现在Java(Scala使用)中,它似乎是Scala特定的问题.

问题:为什么脚本中的超时调用被卡住了?

我该如何解决这个/什么是一个好的解决方法

尝试包含–foreground选项.从男子超时:

–foreground

When not running timeout directly from a shell prompt,allow COMMAND to read from the TTY and receive TTY signals. In this mode,children of COMMAND will not be timed out.

使用以下测试脚本:

#!/bin/bash
/usr/bin/timeout --foreground 10 scala -version
echo "finished with $?"

它似乎工作正常.

$./test.sh 
Scala code runner version 2.9.1 -- copyright 2002-2011,LAMP/EPFL
finished with 1

没有–foreground脚本会像你所描述的那样挂起.

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...