Name: rl43681 Date: 01/28/2004
A DESCRIPTION OF THE REQUEST :
When starting a subprocess with Runtime.exec(), it is not possible to pass on open file descriptor to be used as stdin, stdout or stderr. Consequently all three streams can not be easily redirected.
To operate a legacy application which was designed to read from standard input
and write from standard output requires the java application to
a) Start this process,
b) obtain input and output streams of the process via Process.getInputStream() etc.
c) shuffle data into and out of the process, even if the input is a file or some other open connection, like a socket.
JUSTIFICATION :
The mode of operation described above is (a) inefficient and (b) error prone because deadlocks have to be prevented, requiring the use of Selectors or of up to three threads (in, out, err) to operate the legacy application.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Runtime.exec() should have additional arguments of type InputStream and
OutputStream or of type FileDescriptor which specify source and sink for
the executed process's in, out and error streams.
CUSTOMER SUBMITTED WORKAROUND :
Create three threads to write and read in, out and error stream of the child
process. Make sure you correctly handle partial reads/writes, IOExceptions,
InterruptedIOExceptions, and know how to wait for all three threads to
finish in some order. The code for one such thread is more lines than
reasonably fit in here.
(Incident Review ID: 235817)
======================================================================