• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

console output

 
arjun rampal
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use your operating systems' capabilities; i.e.,

java MyClass > output.log
 
arjun rampal
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi but it is not writing exceptions.
only system.out.println is written.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your cron command looks fine. To append, use ">> a.txt" instead of "> a.txt".
 
arjun rampal
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
finally thanks
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could of course also redirect System.out and System.err to a stream that writes to a file instead.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic