Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > external processes

Reply
Thread Tools

external processes

 
 
trstag75@yahoo.fr
Guest
Posts: n/a
 
      02-21-2007
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?

 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      02-21-2007
On 21 Feb 2007 11:45:24 -0800, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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

--
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
 
 
 
trstag75@yahoo.fr
Guest
Posts: n/a
 
      02-21-2007
On Feb 21, 8:35 pm, Gordon Beaton <(E-Mail Removed)> wrote:
> On 21 Feb 2007 11:45:24 -0800, (E-Mail Removed) wrote:
>
> > 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.


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

Tristan


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Controlling processes and what to "feed" other processes Marc Heiler Ruby 1 05-24-2009 05:37 PM
Monitoring external processes arunasunil@gmail.com Python 4 10-23-2007 07:08 PM
Using exec() to run external processes John English Java 6 10-27-2005 09:32 AM
External Processes Darren Smith Perl 1 10-12-2004 03:14 AM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM



Advertisments