Home arrow static arrow Java Programming [Archive] - Process and IO
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Process and IO
This topic has 6 replies on 1 page.

Posts:82
Registered: 3/10/04
Process and IO  
Jul 28, 2004 1:23 PM



 
dear folks,
I have created a Process from an exe
this exe prints out something to the screen in the beginning as the following(matlab code)
//in the beginning fprintf('status=0.1\n');//does more work

I monitor what this process prints out by doing the following:
BufferedReader br=new BufferedReader(new InputStreamReader(process.getInputStream()));String line=br.readLine();//more code


however the first br.readLine() took about 20 secs which is how long the process take entirely.
readLine seems to be blocking until the process is done.
but if I run this exe at the command prompt, it seems to be printing out 'status=0.1' right
away. I tried \r and \n. This does not seem to be a flushing issue because fprintf flushes
automatically.

Why is br.readLine() blocking??
thank you for any enlightment.
 

Posts:13
Registered: 21.07.04
Re: Process and IO  
Jul 28, 2004 2:46 PM (reply 1 of 6)



 
Are you flushing to the command line in the executable? if not, that could explain it.
The only thing I can think about really.
 

Posts:82
Registered: 3/10/04
Re: Process and IO  
Jul 28, 2004 5:44 PM (reply 2 of 6)



 
Yes I'm flushing to the command line in th exe
 

Posts:2,206
Registered: 8/15/02
Re: Process and IO  
Jul 28, 2004 6:36 PM (reply 3 of 6)



 
But are you flushing the fprintf? fflush(NULL) may work
 

Posts:82
Registered: 3/10/04
Re: Process and IO  
Jul 29, 2004 10:11 AM (reply 4 of 6)



 
But are you flushing the fprintf? fflush(NULL) may
work

but there is no such function fflush in matlab
 

Posts:403
Registered: 9/4/03
Re: Process and IO  
Jul 29, 2004 11:30 AM (reply 5 of 6)



 
What's in the more code?

In other words how do you know the br.readLine() is actually taking 20 seconds?

Are you doing a process.wait()? If so, you would be wiating for the .exe to finish before moving on in your code.

Try this:

String line;									// Read STDOUT into a buffer.			while((line = br.readLine()) != null){				// Do something with data here if you wish.			    System.out.println( line );
 

Posts:82
Registered: 3/10/04
Re: Process and IO  
Jul 29, 2004 2:24 PM (reply 6 of 6)



 
What's in the more code?

In other words how do you know the br.readLine() is
actually taking 20 seconds?

Are you doing a process.wait()? If so, you would be
wiating for the .exe to finish before moving on in
your code.

Try this:

String line; // Read STDOUT into a buffer.while((line = br.readLine()) != null){// Do something with data here if you wish.System.out.println( line );

that's the about the same as what I m doing. I don't have process.wait();
here is what the code's like. Timer is something I implemented. the first br.readLine() took about 20 secs

BufferedReader br=new BufferedReader(new InputStreamReader(process.getInputStream()));		System.err.println("after br init");	try{ while (!canceled && !done) {                try {                	Timer timer=new Timer();		                    timer.start();                                        String line=br.readLine();                    timer.stop();                    System.err.println("read took "+timer.getDuration());........
 
This topic has 6 replies on 1 page.