Buffered output from external process?

R

reid

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
 
R

Roedy Green

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
 
R

reid

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
 
C

cbossens73

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
 
R

reid

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.
 

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,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top