The timeout command does not work with Scala - why?

Setup: Ubuntu 12.04, 32 bit; Scala 2.9.1; Java 1.6.0_24

Description:

On the bash command line, the command /usr/bin/timeout 10 scala -version works fine, it gets stuck when executed in a bash script.

Execution on the command line (duration < 1 seconds):

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

The command itself, placed in a bash script, is stuck:

testScript.sh :

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

Running testScript.sh (duration 10 seconds):

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

Note. The problem does not occur with Java (which is used by Scala), it seems to be a Scala problem.

Question: Why is the timeout call in the script stuck?

How can I fix this / What would be a good way?

+6
source share
1 answer

Try turning on the --foreground . From man timeout :

- foreground

If you are not using the timeout directly from the command line, enable COMMAND to read from TTY and receive TTY signals. In this mode, children from COMMAND will not be synchronized.

Using the following test script:

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

It is working fine.

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

Without --foreground script freezes as you described.

+9
source

Source: https://habr.com/ru/post/922923/


All Articles