Solved

System.out redirect

Posted on 2002-04-05
9
892 Views
Last Modified: 2007-12-19
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!

0
Comment
Question by:epastoor
9 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 50 total points
Comment Utility
use System.setOut and System.setErr passing a PrintStream opened on a FileOutputStream
0
 
LVL 19

Expert Comment

by:cheekycj
Comment Utility
0
 
LVL 9

Expert Comment

by:mmuruganandam
Comment Utility
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
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
Depends on which OS your running, and which version of Java.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 9

Expert Comment

by:yongsing
Comment Utility
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) {}
0
 
LVL 3

Expert Comment

by:rjackman
Comment Utility
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
0
 
LVL 9

Expert Comment

by:Venci75
Comment Utility
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
0
 
LVL 9

Expert Comment

by:Venci75
Comment Utility
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
0
 

Expert Comment

by:SpideyMod
Comment Utility
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
stringclean challenge 26 54
wordlen challenge 3 46
Java Message handling in Service Layer 3 37
Java Timer (static) 9 5
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now