I have a program A that receives stdout of another program B in a ByteBuffer through a Pipe.SourceChannel.
The program will read from the ByteBuffer for stdout until it reaches the end of stream (that is, until ByteBuffer’s read() return -1).
Can stdout of program B open and close multiple times in a program’s execution? That is, is it possible that read() return -1, but later program B has additional stdout, in which case program A should do another read() of the ByteBuffer?
Thanks in advance.
Under Linux, you can use NIO for stdin, stdout and stderr, because they are tied to certain character devices, which can be accessed as files. To do this you can open
/proc/self/fd/0,1or2respectively. This doesn’t work for all stream types, or on non-Unix systems, but it may be an option.Once a stream has closed, it is not possible to reopen it, unless it was a file and you were able to obtain the file name.