Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Question about Runtime.exec() stdout/stderr
suicide
post Sep 11 2004, 12:37 PM
Post #1


Member [ Level 2 ]
Group Icon

Group: Members
Posts: 55
Joined: 7-September 04
Member No.: 351



Runtime.exec() stdout/stderr lost after execvp() in C program?


Hello,

I have a C program that is printing one line of text to stdout, then it is replacing the current process with a new one using execvp(), and then the new program is printing many lines of text to stdout.

When I execute the program in a console (Linux), I can see the line printed by the first process followed by the lines printed by the second process.

But when I run the program using Runtime.exec(), the line printed by the first process seems to be thrown away, actually everything the first process writes to stdout gets lost. The first line that can be read from Process' InputStream is the one printed by the second process.

This behaviour is consistent with JDK 1.3.1, 1.4.2 and 1.5.0 RC, so I assume this is not a bug.

My question is, why is it not possible to read the text written by the first process before execvp()? Is there a way to make that work?

I could provide very simple sample code if needed.
Go to the top of the page
 
+Quote Post
iGuest
post Jan 22 2008, 01:01 AM
Post #2


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 0
Joined: 1-November 07
Member No.: 25,869



fflush
Question about Runtime.exec() stdout/stderr

You should fflush(stdout) before Runtime.Exec(). It might just be that the first line gets stuck in the output buffer and never gets flushed to the terminal. The new process probably allocates a new output buffer, losing all the un-flushed output data from the first executable.

-Greg Bronevetsky
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Vc Runtime Lib Error When Run A Program(3)


 



- Lo-Fi Version Time is now: 7th September 2008 - 11:37 PM