I am using ant to start a Java program.
I do not want to "loose" the output, after the program terminates. So I use the property 'output
' to store the output in a file.
<java classname="..." fork="true" output="....txt">
Unfortunately I do not have any console output anymore. What would be a nice way to have the output on the console and in a txt file.
I am looking for an alternative to
ant mytast > myFile.txt
because I do not want, that the "user" has to use shell redirection "> ..". . If he/she does not choose to redirect, the output is lost.
**\*.sql means "in the given directory and inside all of its subdirectories, all the files that end with .sql"
Ant classpath: discussion dir defined before this code is run, and that variable points to your lib directory, which contains all of the jar files needed by your application. This code also creates a variable named class. path which can be referenced later in your Ant script using the variable syntax ${class. path} .
Ant has a way to record output. http://ant.apache.org/manual/Tasks/recorder.html.
A recorder is a listener to the current build process that records the output to a file.
Several recorders can exist at the same time. Each recorder is associated with a file. The filename is used as a unique identifier for the recorders. The first call to the recorder task with an unused filename will create a recorder (using the parameters provided) and add it to the listeners of the build. All subsequent calls to the recorder task using this filename will modify that recorders state (recording or not) or other properties (like logging level).
It looks like meets your need.
<compile >
<record name="log.txt" action="start"/>
<javac ...
<record name="log.txt" action="stop"/>
<compile/>
If the program writes to one file descriptor (e.g. standard out), you can redirect it to only one place (so either console, or file, not both).
To achieve multiple redirection, you have two options:
I would not recommend the second approach as it makes your code messy and you often do not have full control over what is written to say standard error (think of calls to 3rd party functions).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With