Question about Runtime.exec() stdout/stderr

free web hosting
Free Web Hosting > Computers & Tech > Programming > Programming General > C, C++ & Visual C++

Question about Runtime.exec() stdout/stderr

suicide
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.

Reply

iGuest
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

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. php stdout is not printed in console - 19.77 hr back. (1)
  2. php exec stdout - 23.56 hr back. (1)
  3. runtime.exec() - 39.31 hr back. (1)
  4. linux stderr exec - 46.51 hr back. (1)
  5. run a program and get stdout in c - 49.25 hr back. (1)
  6. java runtime exec get standard out from c - 55.23 hr back. (1)
  7. exec stderr - 60.81 hr back. (1)
  8. runtime.exec buffer - 68.70 hr back. (1)
  9. java exec stdout - 68.75 hr back. (1)
  10. runtime.exec stdout - 71.10 hr back. (1)
  11. stdout exec stderr - 73.22 hr back. (1)
  12. runtime exec sample - 94.80 hr back. (1)
  13. c exec example stdout - 110.11 hr back. (1)
  14. runtime.exec sample - 149.23 hr back. (1)
Similar Topics

Keywords : question, runtime, exec, stdout, stderr

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


      Looking for question, runtime, exec, stdout, stderr

Searching Video's for question, runtime, exec, stdout, stderr
advertisement




Question about Runtime.exec() stdout/stderr



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE