Buffered output from external process?

Discussion in 'Java' started by reid, Apr 8, 2009.

  1. reid

    reid Guest

    Hi. I'm developing a Java app that will run on Windows. I need to
    exec an external process and read its stdout to verify that it's
    started correctly. (It should never exit until my app does.) I've
    written some code that uses ProcessBuilder to execute the process,
    which seems to work fine. I've redirected its error stream to the
    output stream, and I've created a thread to monitor the input. I
    never get anything, though. The app only writes about ten lines, so
    I'm guessing that the app is buffering its output so my Java app never
    sees it. (This is backed up by seeing that, in cmd.exe, I can
    redirect the output to a file and never see it in the file until the
    app exits.) Unfortunately, this is a third party commercial app, so I
    can't modify it. Is there some way to force the app's output to be
    unbuffered? I suppose this is more of a Windows question, but I
    thought I'd check here to see if anyone has come up with a solution.
    TIA!

    Reid
     
    reid, Apr 8, 2009
    #1
    1. Advertising

  2. reid

    Roedy Green Guest

    On Wed, 8 Apr 2009 11:52:52 -0700 (PDT), reid <>
    wrote, quoted or indirectly quoted someone who said :

    >t. (This is backed up by seeing that, in cmd.exe, I can
    >redirect the output to a file and never see it in the file until the
    >app exits.


    see http://mindprod.com/jgloss/exec.html for thread code to handle
    this.
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com

    "At this point, 29 percent of fish and seafood species have collapsed - that is,
    their catch has declined by 90 percent. It is a very clear trend, and it is accelerating.
    If the long-term trend continues, all fish and seafood species are projected to collapse
    within my lifetime -- by 2048."
    ~ Dr. Boris Worm of Dalhousie University
     
    Roedy Green, Apr 8, 2009
    #2
    1. Advertising

  3. reid

    reid Guest

    On Apr 8, 3:27 pm, Roedy Green <>
    wrote:
    > On Wed, 8 Apr 2009 11:52:52 -0700 (PDT), reid <>
    > wrote, quoted or indirectly quoted someone who said :
    >
    > >t.  (This is backed up by seeing that, in cmd.exe, I can
    > >redirect the output to a file and never see it in the file until the
    > >app exits.

    >
    > seehttp://mindprod.com/jgloss/exec.htmlfor thread code to handle
    > this.


    I'd actually already seen that page, and I'd added a thread to handle
    reading from the app's stdout. Still nothing, which is what led me to
    believe that the problem is actually the app itself (or Windows)
    buffering its output before it ever gets to the pipe and to my Java
    app. Is this likely not the case?

    Thanks,
    Reid
     
    reid, Apr 8, 2009
    #3
  4. reid

    Guest

    On Apr 8, 10:50 pm, reid <> wrote:
    > On Apr 8, 3:27 pm, Roedy Green <>
    > wrote:
    >
    > > On Wed, 8 Apr 2009 11:52:52 -0700 (PDT), reid <>
    > > wrote, quoted or indirectly quoted someone who said :

    >
    > > >t. (This is backed up by seeing that, in cmd.exe, I can
    > > >redirect the output to a file and never see it in the file until the
    > > >app exits.

    >
    > > seehttp://mindprod.com/jgloss/exec.htmlforthread code to handle
    > > this.

    >
    > I'd actually already seen that page, and I'd added a thread to handle
    > reading from the app's stdout. Still nothing, which is what led me to
    > believe that the problem is actually the app itself (or Windows)
    > buffering its output before it ever gets to the pipe and to my Java
    > app. Is this likely not the case?


    There are so many things that can go wrong (and that *shall* go
    wrong) when executing external processes from Java on different
    OSes / OSes configuration that I took a much, much more radical
    approach.

    I posted about it here in another thread, where another person
    was having yet another "external process output stream parsing
    problem".

    I decided, years ago (way before Sun programmers even tought
    about coming with the ProcessBuilder hack to try to fix all
    that was wrong/complicated with executing external processes),
    to make sure my external processes were generating exactly
    *zero* output on stdout/stderr and take exactly zero input
    from stdin.

    I made my external process write their output to files:
    plain, simple and radical.

    Sure, you have to parse the file instead of the output streams,
    but this proved much simpler (and it's actually deployed on
    countless OS X and Windows machines).

    Just an idea,

    Charles
     
    , Apr 9, 2009
    #4
  5. reid

    reid Guest

    On Apr 9, 4:39 am, wrote:
    > On Apr 8, 10:50 pm, reid <> wrote:
    >
    >
    >
    > > On Apr 8, 3:27 pm, Roedy Green <>
    > > wrote:

    >
    > > > On Wed, 8 Apr 2009 11:52:52 -0700 (PDT), reid <>
    > > > wrote, quoted or indirectly quoted someone who said :

    >
    > > > >t.  (This is backed up by seeing that, in cmd.exe, I can
    > > > >redirect the output to a file and never see it in the file until the
    > > > >app exits.

    >
    > > > seehttp://mindprod.com/jgloss/exec.htmlforthreadcode to handle
    > > > this.

    >
    > > I'd actually already seen that page, and I'd added a thread to handle
    > > reading from the app's stdout.  Still nothing, which is what led me to
    > > believe that the problem is actually the app itself (or Windows)
    > > buffering its output before it ever gets to the pipe and to my Java
    > > app.  Is this likely not the case?

    >
    > There are so many things that can go wrong (and that *shall* go
    > wrong) when executing external processes from Java on different
    > OSes / OSes configuration that I took a much, much more radical
    > approach.
    >
    > I posted about it here in another thread, where another person
    > was having yet another "external process output stream parsing
    > problem".
    >
    > I decided, years ago (way before Sun programmers even tought
    > about coming with the ProcessBuilder hack to try to fix all
    > that was wrong/complicated with executing external processes),
    > to make sure my external processes were generating exactly
    > *zero* output on stdout/stderr and take exactly zero input
    > from stdin.
    >
    > I made my external process write their output to files:
    > plain, simple and radical.
    >
    > Sure, you have to parse the file instead of the output streams,
    > but this proved much simpler (and it's actually deployed on
    > countless OS X and Windows machines).
    >
    > Just an idea,


    Hi Charles. Thanks. I, too, thought about using files.
    Unfortunately, in my case I can't modify the source code, so the best
    I could do is redirect the output to a file. And I've already tested
    that and seen that the output to the file also gets buffered, so it
    doesn't help me. But that's a good idea in general.

    I guess I was hoping that there might be some utility or Windows
    setting that would force an application's output to be unbuffered, but
    I haven't found anything like that.
     
    reid, Apr 9, 2009
    #5
    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. Guifre
    Replies:
    1
    Views:
    428
    Thomas Weidenfeller
    May 24, 2005
  2. Brian Elmegaard
    Replies:
    2
    Views:
    1,005
    Robert Amesz
    Sep 10, 2003
  3. Replies:
    9
    Views:
    706
    Michael Wojcik
    Aug 23, 2005
  4. Jeff Wood
    Replies:
    1
    Views:
    114
    aurelianito
    Oct 22, 2005
  5. Chris
    Replies:
    3
    Views:
    251
    Brian McCauley
    Mar 16, 2005
Loading...

Share This Page