2016-03-30 41 views
0

我正在從ant文件執行shell腳本。我想在日誌文件'buillog-perform.txt'中捕獲shell腳本的stdoutput。 以下是我對代碼的摘錄。我的完整版本很好。但是shell腳本都不會被執行,也不會在buillog-perform.txt文件中捕獲日誌。將ant腳本中的exec元素的輸出指向日誌文件

有人可以幫助我嗎?如何收集所有的輸出和錯誤,如果任何shell腳本到這個日誌文件?

注:我想要並行執行這個目標,因此使用spawn屬性。

<target name="perform" 
     description="This target for the perform.">  
    <exec dir="." executable="/bin/sh" spawn="true" output="buillog-perform.txt"> 
      <arg line="-c './abc.sh -c ${arg1}'" /> 
    </exec> 
</target> 
+1

有在ANT EXEC任務的「輸出」屬性:請參閱:https://ant.apache.org/manual/Tasks/exec.html –

回答

0

我建議你以下解決方案之一:

1)修改代碼:

<arg line="-c './abc.sh -c ${arg1}' > stdout.txt 2> stderr.txt" /> 

2)添加下面一行在你的bash腳本的開頭:

#!/bin/bash 
exec &>> logfile.txt 
… 

注意>>是要追加的,而>只會寫即另外,您可以使用> outANDerr.txt 2>&1將所有輸出都放在同一個文件中。

欲瞭解更多信息看看這裏:http://wiki.bash-hackers.org/syntax/redirection

相關問題