Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

System.err.println & System.out.println

 
Susilo Saja
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guyz,
Seem to me that System.err.println and System.out.println give the same result, printing to the console. What is the different?
Or is it possible to set the output destination of those two method?
Susilo
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
its all age old OS conventions to have three basic type of streams,
1. standard input (File descriptor: 0)
2. standard output (file descriptior: 1)
3. standard error (file descriptor: 2)
usually, error and output are pointing to the same "physical device" as output that is Screen.
u can try,
this link and following program for demo,

now, to run this.
first try running like,
bash$java ErrOut
you will get out put on the screen,
This should go to Standard Output
This should go to Standard Error
Now, run this like,
bash$java ErrOut 2> TempErrorFile
(OBSERVE THE '>' RIGHT AFTER 2 WHICH IS A STD_ERR descriptor)
you'll get following output on the screen,
This should go to Standard Output
now do,
bash$cat TempErrorFile then u'll see the line,
This should go to Standard Error

well, this is how it works on Unix/Linux. i didnt try with windows.
hope this is helpful.
regards
maulin
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
forgot to mention
try,
bash$java ErrOut 1> TempFile
then see what u get
regards
maulin
 
Susilo Saja
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Maulin, that was a great reply.
I've tried the same on Windows and it worked
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic