Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I ensure all output from Ant's exec task goes to stdout?

Tags:

The Ant exec task has an output property which can be used to tell Ant where the output goes. I've used it to redirect the output to a file. The thing is, if I don't do something with the output, the stuff that Ant prints isn't that much of a help - it's not complete.

Is there someway of setting the output property to System.out?

like image 959
Geo Avatar asked Oct 21 '09 18:10

Geo


2 Answers

When executing a batch file with ant's apply or exec tasks on Windows, I found there are special cases where some of the stdout and stderr is not captured by ant. (For example: if you call a batch file that in turn calls other commands (like node.exe), then the stdout and stderror from the child node.exe process is lost.)

I spent a long time trying to debug this! It seems that the batch file's stdout and stderr is captured, however commands called by the batch file are somehow not seen by ant. (perhaps because they are separate child processes). Using the output and error attributes as suggested above doesn't help because only some of the stdout and/or stderr is captured.

The solution I came up with (a hack) is to add these arguments at the end of the command:

<!--Next arg: forces node's stderror and stdout to a temporary file-->
<arg line=" &gt; _tempfile.out 2&lt;&amp;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 &amp; del _tempfile.out &amp; exit /b 1)"/>

<!--Next arg: Otherwise, just type the temporary file and delete it-->
<arg line=" &amp; type _tempfile.out &amp; del _tempfile.out &amp;"/>

Because this hack only applies to windows, remember to add @osfamily="windows" to the apply or exec task. And create similar task(s) for `@osfamily="unix", etc but without these extra arguments.

like image 144
darcyparker Avatar answered Sep 17 '22 10:09

darcyparker


The output of exec does go to standard out unless you specify the output attribute.

like image 21
Jonathan Feinberg Avatar answered Sep 18 '22 10:09

Jonathan Feinberg