Russel Winder | 1 Dec 2004 15:13
Picon
Gravatar

Re: Is this a buffering problem?

On Wed, 2004-12-01 at 12:22, Guillaume Laforge wrote:
> Russel Winder wrote:
> > It does seem that this is the case doesn't it.  I am not sure how that
> > can happen though, I would have thought that javaProcess.out was a
> > stream to the process and not an alias for System.out.
> 
> It's not an alias to System.out!
> javaProcess.out is equivalent to javaProcess.getOutputStream().
> That's the stream you can use to write to the process' input stream.

Exactly what I thought.  The problem is though that the line:

	javaProcess.in.println("3")

appears to have resulted in the string "3\n" being sent to the console
and not to the process.  I even tried replacing the Java program with a
standard executable:

#! /usr/bin/env groovy
process = "tee flob".execute()
process.out.println("3")
process.getOut().println("4")
process.getOutputStream().println("5")
System.out.println("6")

which results in a file flob on the file system of size zero when it
should be of size 6 and the characters "3\n4\n5\n6\n" appearing on the
console.  Something somewhere is making all the lines that should be
sending characters to the spawned process behave identically to the last
line which simply send a character to the console.

I ferreted a little more and thought:  Hang on a minute println is only
applicable to a PrintStream or PrintWriter and the result of
Process.getOutputStream should be an OutputStream.  In fact it delivers
a BufferedOutputStream which is totally the wrong thing to do in my view
(Ross Burton and I found this problem a few months ago and submitted a
bug report 5008462 but it seems that Sun have decided that this is not a
bug when actually it is :-(  So the question is why does the above
compile -- the method println is not applicable to a
BufferedOutputStream.

--

-- 
Russel.
=============================================
Dr Russel Winder         +44 20 7585 2200
41 Buckmaster Road       +44 7770 465 077
London SW11 1EN, UK      russel@...


Gmane