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