Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Buffered output from external process?

Reply
Thread Tools

Buffered output from external process?

 
 
reid
Guest
Posts: n/a
 
      04-08-2009
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
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      04-08-2009
On Wed, 8 Apr 2009 11:52:52 -0700 (PDT), reid <(E-Mail Removed)>
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
 
Reply With Quote
 
 
 
 
reid
Guest
Posts: n/a
 
      04-08-2009
On Apr 8, 3:27*pm, Roedy Green <(E-Mail Removed)>
wrote:
> On Wed, 8 Apr 2009 11:52:52 -0700 (PDT), reid <(E-Mail Removed)>
> 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
 
Reply With Quote
 
cbossens73@yahoo.fr
Guest
Posts: n/a
 
      04-09-2009
On Apr 8, 10:50 pm, reid <(E-Mail Removed)> wrote:
> On Apr 8, 3:27 pm, Roedy Green <(E-Mail Removed)>
> wrote:
>
> > On Wed, 8 Apr 2009 11:52:52 -0700 (PDT), reid <(E-Mail Removed)>
> > 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

 
Reply With Quote
 
reid
Guest
Posts: n/a
 
      04-09-2009
On Apr 9, 4:39*am, (E-Mail Removed) wrote:
> On Apr 8, 10:50 pm, reid <(E-Mail Removed)> wrote:
>
>
>
> > On Apr 8, 3:27 pm, Roedy Green <(E-Mail Removed)>
> > wrote:

>
> > > On Wed, 8 Apr 2009 11:52:52 -0700 (PDT), reid <(E-Mail Removed)>
> > > 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.
 
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
logging buffered vs. logging history Christian Roos Cisco 4 02-05-2006 10:55 PM
RDT under windows ... output buffered ??? Jeff Wood Ruby 1 10-22-2005 12:07 AM
whether is the standard input stream full buffered or line buffered after calling function setbuf()? kernelxu@hotmail.com C Programming 9 08-23-2005 02:24 PM
How to read buffered output from ping-like process Chris Perl Misc 3 03-16-2005 05:46 PM
sending web response wihout buffered =?Utf-8?B?TWVobWV0?= ASP .Net 1 01-13-2004 11:55 AM



Advertisments