JDK-4447134 : (process) Add Process.set{Output,Error}Stream methods
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.3.0,1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2001-04-18
  • Updated: 2011-05-25
  • Resolved: 2011-05-25
Related Reports
Duplicate :  
Relates :  
Description
F

Name: krC82822			Date: 04/18/2001


[18 Apr 2001, eval1127@eng -- filing this under classes_lang
because, while motivated by a JDI/JPDA issue, the requested
changes must be made in Process]

java version "1.3.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_02)
Java HotSpot(TM) Client VM (build 1.3.0_02, mixed mode)

I'm launching new VirtualMachine instances by calling
com.sun.jdi.connect.LaunchingConnector.launch( java.util.Map )

The documentation for this method states:
( at http://java.sun.com/j2se/1.3/docs/guide/jpda/jdi/index.html )

"Important note: If a target VM is launched through this function, its output
and error streams must be read as it executes. These streams are available
through the Process object returned by VirtualMachine.process(). If the streams
are not periodically read, the target VM will stop executing when the buffers
for these streams are filled."

Fine, so I call VirtualMachine.process() and then periodically call
Process.getOutputStream().flush() to empty the buffer, and likewise with the
error stream.

However, it is highly desirable to simply redirect the output and error
streams of a given Process.  For example, from my JDI application, call
Process.setOutputStream( System.out ) and Process.setErrorStream( System.err )
This would require the addition of these two methods to java.lang.Process

Furthermore, it would be even more desireable to get notification of events in
the streams of a given Process... this could be implemented in the stream API,
or the process API; either way, something to allow for notification that the
stream buffers have received data.  That way, my application will automatically
flush them, but only when needed, not periodically as the documentation for
com.sun.jdi.connect.LaunchingConnector.launch( java.util.Map ) would impose.

If the JPDA is to become a full fledged standard, silly things like periodic
polling of a launched Process's output stream will have to go.
(Review ID: 120960) 
======================================================================

Comments
EVALUATION Support for redirection was added to jdk7 via 4960438.
25-05-2011

WORK AROUND Name: krC82822 Date: 04/18/2001 Polling of the launched Process's output streams. ======================================================================
11-06-2004

EVALUATION Adding setOutputStream and setErrorStream methods to java.lang.Process is not an unreasonable idea. Will consider further. -- mr@eng 2001/4/19 If we decide to procede with this, setting Output/Error stream should be done atomically at the same time the process is executed, so we will probable need a couple of additional exec() methods which take streams. We will also need to start threads, which will wait on native pipes and transfer bytes from them to OutputStreams. In the case, when the user sets streams, corresponding GetOutput/Error stream methods should probably be disabled. ###@###.### 2002-05-25
25-05-2002