2016-03-30 39 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

相关问题