Solved

System.out redirect

Posted on 2002-04-05
9
904 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 86

Accepted Solution

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

Expert Comment

by:cheekycj
ID: 6921520
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 6921717
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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 92

Expert Comment

by:objects
ID: 6921959
Depends on which OS your running, and which version of Java.
0
 
LVL 9

Expert Comment

by:yongsing
ID: 6922512
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
ID: 6924689
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
ID: 7933233
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
ID: 7973707
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
ID: 8020313
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Certificat to iSeries KeyStore 1 31
Unhandled exception type Exception 18 65
web project error add remove 1 84
What browser will run Java? 7 181
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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…
Suggested Courses

751 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