stdout and stderr don't occur sequentially in Eclipse and Netbeans  
Author Message
Lew





PostPosted: 2008-6-24 21:09:00 Top

java-programmer, stdout and stderr don't occur sequentially in Eclipse and Netbeans ZelluX wrote:
> But System.err is unbuffered, so I don't think it will have any effect
> to flush after every write.

There is nothing in the Javadocs to indicate that System.err is unbuffered.
Like System.out, System.err is a java.io.PrintStream. The docs for
PrintStream imply that instances are buffered, else the flush() method would
be meaningless. So it is not accurate, or at least not safe to say that
System.err is unbuffered.

That leaves auto-flushing. Nothing in the Javadocs for System.err indicates
that it's created with autoFlush on. Did you check the source for your
particular flavor of Java to see if it is?

In my installation, the source shows:
setErr0(new PrintStream(new BufferedOutputStream(fdErr, 128), true));

Whaddaya know? System.err is buffered in my installation.

Sun Java JDK 1.6.0_10b25, 64 bit, Linux.

Are you quite certain that System.err is unbuffered in your Java installation?

--
Lew
 
Andrea Francia





PostPosted: 2008-6-25 7:10:00 Top

java-programmer >> stdout and stderr don't occur sequentially in Eclipse and Netbeans ZelluX wrote:
> I'm not that certain, but I've tried placing a System.err.flush()
> after the output, and it doesn't work.
> Under consoles like Windows CMD or Linux bash, the problem won't occur.

The way that cmd or linux bash deal with the std out end the std err of
a child process may be different from the way that netbeans (or eclipse)
deal with them.

--
Andrea Francia
http://andreafrancia.blogspot.com/2008/06/relazioni-molti-molti-con-jpa.html
 
Andrea Francia





PostPosted: 2008-6-25 7:16:00 Top

java-programmer >> stdout and stderr don't occur sequentially in Eclipse and Netbeans ZelluX wrote:
>
> My problem is, in the situatations which both stdout and stderr are to
> be printed on the console, is it possible to make them occur in the
> order that they're called?
>
> I just found this odd behaviour in some IDEs and are curious to know
> whether there are any APIs with function like setvbuf ;-)

Even if the standard error and output steams are flushed in a specific
order you don't have no promise on what order the reading process (the
IDE or the shell) decide to output them.

To know this you should read the specification (if there are any) of the
reading process.

--
Andrea Francia
http://andreafrancia.blogspot.com/2008/06/relazioni-molti-molti-con-jpa.html
 
 
Arne Vajh鴍





PostPosted: 2008-6-25 8:07:00 Top

java-programmer >> stdout and stderr don't occur sequentially in Eclipse and Netbeans ZelluX wrote:
> In linux there's a function setvbuf which can make stdout and stderr
> line-buffered (_IOLBF mode), and thus the similar problem in C
> programming can be resolved.
>
> Is there anything like setvbuf in Java?

Not really.

I think the keyword in what you wrote is "in Linux" - Java is
platform independent and it could be a difficult problem to
implement such functionality on all platforms.

You van still use Patricias workaround.

Arne