external processes

Discussion in 'Java' started by trstag75@yahoo.fr, Feb 21, 2007.

  1. Guest

    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?
    , Feb 21, 2007
    #1
    1. Advertising

  2. On 21 Feb 2007 11:45:24 -0800, 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
    Gordon Beaton, Feb 21, 2007
    #2
    1. Advertising

  3. Guest

    On Feb 21, 8:35 pm, Gordon Beaton <> wrote:
    > On 21 Feb 2007 11:45:24 -0800, 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
    , Feb 21, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Darren Smith

    External Processes

    Darren Smith, Oct 12, 2004, in forum: Perl
    Replies:
    1
    Views:
    462
    J├╝rgen Exner
    Oct 12, 2004
  2. John English
    Replies:
    6
    Views:
    451
    John English
    Oct 27, 2005
  3. Jeff Rodriguez
    Replies:
    23
    Views:
    1,084
    David Schwartz
    Dec 9, 2003
  4. Replies:
    4
    Views:
    725
  5. Marc Heiler
    Replies:
    1
    Views:
    161
    Robert Klemme
    May 24, 2009
Loading...

Share This Page