Reputation: 466
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
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