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
?
When executing a batch file with ant's
apply
orexec
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 (likenode.exe
), then the stdout and stderror from the childnode.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
anderror
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:
Because this hack only applies to windows, remember to add
@osfamily="windows"
to theapply
orexec
task. And create similar task(s) for `@osfamily="unix", etc but without these extra arguments.If you want to output to System.out, then simply do not specify the "output" attribute. If you would like to redirect to a file AND print it to System.out, you can use the tee command, which will redirect output to a given file and also echo it to standard out... I do not know if Windows supports "tee" or an equivalent.
Maybe you want to look at the
error
,logError
, anderrorproperty
attributes of the exec task too. These deal with the handling of the standard error stream from the exec'd process. There may be useful information there that is going awol for some reason - which might account for the incompleteness you see.But, if the exec'd process decides to close stdout or stderr and send them elsewhere - there's little you can do.
The output of
exec
does go to standard out unless you specify theoutput
attribute.I have faced similar problem: the output of command execution was suppressed. Perhaps that is the side effect when running
cmd
under WinXP (I an usingmaven-antrun-plugin
). Anyway settingoutput="con"
worked out perfectly:I was experiencing this same kind of issue trying to get the build process to fail in Ant after Karma tests intentionally failed, and executing them with "grunt test".
Just added /c before "grunt test", and it worked like a charm