这是一个简单的bash脚本,它应该运行另一个脚本重定向stdin stdout并退出状态
timeout $time $assessment_tests/elaborato.sh $parametri < stdin.txt > stdout.txt 2> stderr.txt
echo $? > exit.txt
第一行正常,但第二行打印出&#39; 0&#39;即使脚本elaborato.sh遇到错误,也在文件中。为什么? 显然没有超时&#39;命令打印正确的退出状态。有什么建议吗?
答案 0 :(得分:4)
从timeout
手册页:(显示第一个选项......)
--preserve-status
=返回命令的状态,即使发生超时。
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