Ant exec任务有一个输出属性,可用于告诉Ant输出的位置.我用它将输出重定向到文件.问题是,如果我不对输出做些什么,那么Ant打印的东西并没有那么大的帮助 - 它并不完整.
有没有设置输出属性System.out?
dar*_*ker 16
在Windows上执行带有ant apply或exec任务的批处理文件时,我发现有些特殊情况下ant没有捕获某些stdout和stderr.(例如:如果您调用批处理文件,而该批处理文件又调用其他命令(如node.exe),则子node.exe进程中的stdout和stderror将丢失.)
我花了很长时间试图调试这个!似乎批处理文件的stdout和stderr被捕获,但批处理文件调用的命令在某种程度上不被ant看到.(也许是因为它们是独立的子进程).使用上面建议的output和error属性没有用,因为只捕获了一些 stdout和/或stderr.
我提出的解决方案(一个hack)是在命令的末尾添加这些参数:
<!--Next arg: forces node's stderror and stdout to a temporary file-->
<arg line=" > _tempfile.out 2<&1"/>
<!--Next arg: If command exits with an error, then output the temporary file to stdout, -->
<!--delete the temporary file and finally exit with error level 1 so that -->
<!--the apply task can catch the error if @failonerror="true" -->
<arg line=" || (type _tempfile.out & del _tempfile.out & exit /b 1)"/>
<!--Next arg: Otherwise, just type the temporary file and delete it-->
<arg line=" & type _tempfile.out & del _tempfile.out &"/>
Run Code Online (Sandbox Code Playgroud)
因为这个hack只适用于windows,所以请记住添加@osfamily="windows"到apply或exec任务.并为`@ osfamily ="unix"等创建类似的任务,但没有这些额外的参数.