Link to home
Start Free TrialLog in
Avatar of epastoor
epastoor

asked on

System.out redirect

Anyone know of a way to redirect the output that the java engine creates to a text file? For example, if your program crashes due to a null pointer, the dos-console window prints out a list of like 15 lines or so with the error and where it occurred. Well, my console window's buffer is not always large enough for me to see what the last line of code that was executed.  Id like to somehow send this to a text file for reading.  Thanks!

ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hai epastoor,


   It is very simple.  In order to redirect your console messages to a file,

you need to the following

for eg.,

java MyClass > console.log


after your program completion, you can open the console.log to see the outputs (System.out.println's)


All the best
Muruganantham
Depends on which OS your running, and which version of Java.
Avatar of yongsing
yongsing

The following will redirect all exception stack trace to a file named "errors.log":

try {
  System.setErr(new PrintStream(new FileOutputStream("errors.log", true)));
} catch (FileNotFoundException fileNotFoundException) {}
u can also use the following

javac -Djavac.pipe.output=true myfile.java > errors.txt
where myfile.java is your class file for compilation

cheers
RJ
This question has been abandoned. I will make a recommendation to the moderators on its resolution in a week or two. I appreciate any comments that would help me to make a recommendation.

In the absence of responses, I may recommend
Answered by: CEHJ
Silence = you don't care

Venci75
EE Cleanup Volunteer
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by: CEHJ
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venci75
EE Cleanup Volunteer
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange