[ACCEPTED]-How can we redirect a Java program console output to multiple files?-eclipse
Go to run as and choose Run Configurations
-> Common
and in the 2 Standard Input and Output you can choose 1 a File also.
You could use a "variable" inside the output 8 filename, for example:
/tmp/FetchBlock-${current_date}.txt
current_date:
Returns 7 the current system time formatted as yyyyMMdd_HHmm. An 6 optional argument can be used to provide 5 alternative formatting. The argument must 4 be valid pattern for java.util.SimpleDateFormat.
Or 3 you can also use a system_property or an 2 env_var to specify something dynamic (either 1 one needs to be specified as arguments)
You can set the output of System.out programmatically 9 by doing:
System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream("/location/to/console.out")), true));
Edit:
Due to the fact that this 8 solution is based on a PrintStream
, we can enable autoFlush, but 7 according to the docs:
autoFlush - A boolean; if 6 true, the output buffer will be flushed whenever 5 a byte array is written, one of the println 4 methods is invoked, or a newline character 3 or byte ('\n') is written
So if a new line 2 isn't written, remember to System.out.flush()
manually.
(Thanks 1 Robert Tupelo-Schneck)
To solve the problem I use ${string_prompt} variable. It 4 shows a input dialog when application runs. I 3 can set the date/time manually at that dialog.
We can do this by setting out variable of 7 System class in the following way
System.setOut(new 6 PrintStream(new FileOutputStream("Path 5 to output file"))). Also You need to 4 close or flush 'out'(System.out.close() or 3 System.out.flush()) variable so that you 2 don't end up missing some output.
Source 1 : http://xmodulo.com/how-to-save-console-output-to-file-in-eclipse.html
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.