File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes console output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "console output" Watch "console output" New topic
Author

console output

arjun rampal
Ranch Hand

Joined: Jul 08, 2005
Posts: 125
Hi
running application with jdk
whether console output for application is saved anywhere inside jdk folders.
if No how it can be save to some file .

regards
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Use your operating systems' capabilities; i.e.,

java MyClass > output.log


[Jess in Action][AskingGoodQuestions]
arjun rampal
Ranch Hand

Joined: Jul 08, 2005
Posts: 125
Hi but it is not writing exceptions.
only system.out.println is written.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Again, use your operating system's capabilities; the syntax differs depending on what OS and shell you're using, but even on recent versions of Windows, it's possible to redirect standard error. Let us know what OS we're talking about, and I'm sure someone will tell you what to do.
arjun rampal
Ranch Hand

Joined: Jul 08, 2005
Posts: 125
I am developing and testing on windows and deploying on red hat linux so both i need.
for windows I am using java ar.jar>c:/a.txt. for linux i dont know how to write command for saving on file

And I need to show both exception and system.out in a.txt
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Well, I know for sure how to do it on Linux (using the default shell "bash"):

java -jar ar.jar > a.txt 2>&1

On Windows XP, I'm not positive, but I believe you would just say

java -jar ar.jar > a.txt 2>a.txt

On older versions of Windows, you're out of luck; they don't have this capability.
arjun rampal
Ranch Hand

Joined: Jul 08, 2005
Posts: 125
Almost reached to solution with one issue.
on window if i give file name as same it gives error "process can not access file because it is used by another process."
but if i use difernt file name it works with exception save in another file and stdout in another file.
for linux are you sure it wont ask for second file name?as for same file name it is giving error on windows

java -jar ar.jar > a.txt 2>&1

On Windows XP, I'm not positive, but I believe you would just say

java -jar ar.jar > a.txt 2>a.txt
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

On Linux, you can definitely redirect both streams to a single file. Wait, let me go Google the Windows thing... Incredibly, it seems that to do this in Windows, you have to use the Bourne shell syntax -- the same syntax I'm showing you for Linux! In other words

java -jar ar.jar > a.txt 2>&1

should work on Windows XP. Try it and let us know if it works!
arjun rampal
Ranch Hand

Joined: Jul 08, 2005
Posts: 125
Hi ernest thanks for your patience.
leave google search for window i will do that
just let me know one thing

I am using cron to run that jar so script should be like that
/usr/java/j2sdk1.4.2_12/bin/java -jar /home/wasadmin/b.jar
> a.txt 2>&1

is enough? and whether every time jar will run it will overwrite the a.txt or will appned to previous run.
As i want append not overwrite
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Your cron command looks fine. To append, use ">> a.txt" instead of "> a.txt".
arjun rampal
Ranch Hand

Joined: Jul 08, 2005
Posts: 125
finally thanks
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
You could of course also redirect System.out and System.err to a stream that writes to a file instead.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: console output
 
Similar Threads
Main program not giving output
simple code ! char conversion
Signed Applet
Servlet Query
TrayIconDemo on VISTA