on 19cb950 help sign in
35 lines 854 B history raw
1#!/usr/bin/env bash
3# From http://unix.stackexchange.com/questions/43340/how-to-introduce-timeout-for-shell-scripting
4# Here copied from reg039.
5#
6# Executes command with a timeout
7# Params:
8# $1 timeout in seconds
9# $2 command
10# Returns 1 if timed out 0 otherwise
11timeout() {
13 time=$1
15 # start the command in a subshell to avoid problem with pipes
16 # (spawn accepts one command)
17 command="/bin/sh -c \"$2\""
19 expect -c "set echo \"-noecho\"; set timeout $time; spawn -noecho $command; expect timeout { exit 1 } eof { exit 0 }"
21 if [ $? = 1 ] ; then
22 echo "Timeout after ${time} seconds"
23 fi
27declare -a extraargs
28for arg in "$@"
29do
30 extraargs=("${extraargs[@]}" "'$arg'")
31done
33timeout 10 "idris ${extraargs[*]} Main.idr --nocolour --check --warnreach -o basic010"
34timeout 5 "./basic010"
35rm -f *.ibc basic010