Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

System.out redirect

Posted on 2002-04-05
9
Medium Priority
?
907 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 200 total points
ID: 6921484
use System.setOut and System.setErr passing a PrintStream opened on a FileOutputStream
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

721 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