I have bash script to run process in another thread and kill it, if it's hung up after timeout. All works perfectly, BUT when process require '<' as input or '>' to output to another file, it doesn't count them. Code:
#!/bin/bash
($1)&
PID=$!
echo "Program '"$1"' started, PID="$PID
i=1
while [ $i -le 600 ]
do
ps -p $PID >> /dev/null
if [ $? -ne 0 ]
then
wait $PID
exit $? #success, return rc of program
fi
i=$(($i+1))
echo "waiting 1 second..."
sleep 1
done
#program does not want to exit itself, kill it
echo "killing program..."
kill $PID
exit 1 #failed
i use it like this:
safestart.sh './bzip2 -d sample2.bz2 -k'
and all is as expected, but if i use somethig like this:
safestart.sh './cc_dry2 < dhryinput > results'
it doesn't get '<' or '>' symbols. I tried already with "". same result, I'm completely at lost here.
The problem is the line:
($1)&
You should use instead:
eval $1 &
See also the following example for better understanding the problem.
cmd="echo TEST"
$(${cmd})
gives:
TEST: command not found
cmd="echo TEST"
eval ${cmd}
gives:
TEST
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.