tags:

views:

1748

answers:

6

Hi,

I would like to know, where does java stderr standardly go?

I know I can change the stderr using System.setErr, which 'Reassigns the "standard" error output stream.', but I dont know, which one is "standard".

I would like to specify my question more: I have C++ library that I use in java (jni). The problem is that it appears that I cannot see output to stderr, that comes from my C++ library. I call assert () in C++ library and don't see the output in console, when I run the java api that uses the library.

+2  A: 

By default System.err is the console, just like System.out.

Joonas Pulakka
A: 

console i think java sun api

Tobiask
+10  A: 

It goes to the standard error stream of the process, whatever that's set up to be.

  • If you run the application from a console, it will probably write to the console as well.
  • In a GUI, standard out/err are often dropped, i.e. the output is lost.
  • In a service (e.g. a web server) the standard error/output is usually captured in a rotated log file somewhere, but it entirely depends on the service.

Most platforms allow you to redirect the standard error stream somewhere else (e.g. to a text file).

The idea of System.setErr is to allow you to not use the standard error stream of the process itself, but change it so that calls to System.err.println etc go to the given stream.

Jon Skeet
A: 

I've just written a little test program that does a System.err.println and it would appear to be output to the console.

John Topley
+1  A: 
vartec
A: 

This should go to java.io.FileDescriptor.err http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileDescriptor.html

System.setErr(new PrintStream(new BufferedOutputStream(new FileOutputStream(java.io.FileDescriptor.err),128),true));
Mork0075