external processes

T

trstag75

Hi all,

I'd like to know what is a safe way to deal with
an external process which we're *sure* won't
be generating any output on stdout/stderr nor
expecting any output on stdin.

Do I still need to read the InputStream(s)?

Would there still be a risk of being blocked
during the read?

I'd like to avoid having to create a
new unnecessary thread (once again, it is know
for sure that the process won't generate anything
on stdout/stderr) just for reading a stream that
I know shall be empty.

Basically I'm calling a shell script whose whole
point is that it 'wraps' the command to be called,
redirecting stdout/stderr to files (and also making
sure that it shall not block if the wrapped
command happens to expect input on stdin).

So that very simple shell script I'm calling
cannot generate anything on stdout/stderr.
It is convenient in that it eliminates the potential
deadlocks explained in the Process class's
JavaDoc.

JavaDoc (JD) for the Process class :
JD: Because some native platforms only provide
JD: * limited buffer size for standard input and output streams,
failure
JD: * to promptly write the input stream or read the output stream of
JD: * the subprocess may cause the subprocess to block, and even
deadlock

I've read the JavaDoc for ProcessBuilder and Process
and apparently it doesn't mention if reading the InputStream(s)
is mandatory or not.

Any infos on this?
 
G

Gordon Beaton

I'd like to know what is a safe way to deal with an external process
which we're *sure* won't be generating any output on stdout/stderr
nor expecting any output on stdin.

Do I still need to read the InputStream(s)?
No.

Would there still be a risk of being blocked
during the read?

Since the block is caused by a buffer filling, there is no risk if
nothing is ever written.

Just don't forget that you still need to close all three streams (in,
out, err) at some point. There is a file descriptor associated with
each of them, and if you fail to close them you will run out
eventually.

/gordon
 
T

trstag75

Since the block is caused by a buffer filling, there is no risk if
nothing is ever written.

Just don't forget that you still need to close all three streams (in,
out, err) at some point. There is a file descriptor associated with
each of them, and if you fail to close them you will run out
eventually.

Thanks a lot for the infos. I'm working on it at the moment.

Tristan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top