JoulinRouge
JoulinRouge

Reputation: 466

I cannot get the exit status of a script run under timeout

Here is a simple piece of a bash script that should run another script redirecting stdin stdout and exit status

timeout $time $assessment_tests/elaborato.sh $parametri < stdin.txt > stdout.txt 2> stderr.txt 
echo $? > exit.txt

the first line works fine but the second line prints a '0' in the file even if the script elaborato.sh has encountered an error. Why? Obviously without the 'timeout' command is printed the correct exit status. Any suggestions?

Upvotes: 0

Views: 617

Answers (1)

lornix
lornix

Reputation: 2036

From the timeout man page: (very first option shown...)

--preserve-status = Return the command's status, even if timeout occurred.

 NAME
        timeout - run a command with a time limit

 SYNOPSIS
        timeout [OPTION] DURATION COMMAND [ARG]...
        timeout [OPTION]

 DESCRIPTION
        Start COMMAND, and kill it if still running after DURATION.

        Mandatory arguments to long options are mandatory for short options too.

        --preserve-status

               exit with the same status as COMMAND, even when the command times out

Upvotes: 4

Related Questions