I’m using a bash script to automate a set of tests for some other code. The script looks like this:
for i in $(seq 1 10)
do
cd ~/BuildBot
rm -rf program # Remove the directory each time to test installation
git clone /localrepo/
cd ~/into/program
python2.6 setup.py build_ext -i
cd tests
python runtest.py >& ~/into/reptest/runtest-all.out.$i
echo $? > ~/into/reptest/runtest-all.exit.$i
done
When run like this, the script does what I want – shows me a Wall of Text, and saves it to a file in the directory reptest. Now that I’ve tested installation, it’s getting annoying to have to wait for the whole program to reinstall. However, when I cut the script down to
for i in $(seq 1 10)
do
cd ~/into/program/tests
python runtest.py >& ~/into/reptest/runtest-all.out.$i
echo $? > ~/into/reptest/runtest-all.exit.$i
done
The script hangs, nothing happens, the shell waits on a blank line until I Ctrl-C it. What happens to the output? How do I get back my Wall of Text?
Redirects both stdout and stderr from runtest.py into the file ~/into/reptest/runtest-all.out.$i. Your wall of text comes from the statements you’ve pruned away.
What you’re interested in are probably something like:
Which runs python runtest.py in a subshell and redirect it’s stderr to stdout, then pipe the output from that subshell into “tee ~/into/reptest/runtest-all.out.$i”. tee saves it’s stdin to the file given as an argument in addition to copying it to stdout.
As to why your programs waits until you send it SIGINT, I’m not sure, I don’t see anything bash-related which should make your script hang until interrupted.