2009-06-30 113 views
0

我正在使用bash脚本来自动化一些其他代码的测试。该脚本是这样的:重定向测试输出

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 

当这样运行,脚本我想要做什么 - 我展示文本的一堵墙,并将其保存在目录reptest文件。现在我已经测试了安装,现在不得不等待整个程序重新安装。然而,当我将脚本降低到

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 

脚本挂起,没有任何反应,shell在空白行等待,直到我按Ctrl-C它。输出会发生什么?我如何找回我的文字墙?

+0

你没有发生过使用windows/Cygwin并错误地切换到\ r \ n行结尾? – Boldewyn 2009-06-30 15:00:00

回答

0
python runtest.py >& ~/into/reptest/runtest-all.out.$i 

重定向标准输出和标准错误从runtest.py到文件〜/到/ reptest/runTest方法,all.out。$我。你的文本来自你删除的陈述。

你感兴趣的是什么可能是这样的:

(python runtest.py 2>&1) | tee ~/into/reptest/runtest-all.out.$i 

其中在子shell中运行蟒蛇runtest.py并重定向它的标准错误到标准输出,从子shell输出然后通过管道将进入“三通〜/进入/ reptest/runTest方法,all.out。$ I”。除了将它复制到标准输出外,tee还将它保存到作为参数给出的文件中。至于为什么你的程序等待,直到你发送SIGINT,我不确定,我没有看到任何与bash有关的东西,这会让你的脚本挂起直到被中断。