From: FangQ on 8 Dec 2009 10:37 hi I have encountered a strange problem. I am writing a pascal (Lazarus) GUI program to communicate with a C++ command line tool. In the C++ tool, it prints out various informations (with fprintf(stdout, ....) ) during the execution, and I was trying to capture it in the GUI. Strangely, I found that my GUI only print the entire output at the end of the execution. However, if I change the command to a shell command, such as "du /usr/ --max-depth=1", or even the following script: #!/bin/sh echo $@ sleep 1 echo step 1 complete sleep 1 echo step 2 complete sleep 1 echo mcx complete the intermediate output will be captured instantly during the execution. I am wondering if I need to manually flush the pipe in my C++ code? and how to do that? thanks Qianqian
From: Barry Margolin on 8 Dec 2009 15:42 In article <5d1467f9-9087-4ddd-8ad9-2e40d46a2fa6(a)e20g2000vbb.googlegroups.com>, FangQ <fangqq(a)gmail.com> wrote: > hi > > I have encountered a strange problem. I am writing a pascal (Lazarus) > GUI program to communicate with a C++ command line tool. In the C++ > tool, it prints out various informations (with fprintf(stdout, ....) ) > during the execution, and I was trying to capture it in the GUI. > > Strangely, I found that my GUI only print the entire output at the end > of the execution. However, if I change the command to a shell command, > such as "du /usr/ --max-depth=1", or even the following script: > > #!/bin/sh > echo $@ > sleep 1 > echo step 1 complete > sleep 1 > echo step 2 complete > sleep 1 > echo mcx complete > > the intermediate output will be captured instantly during the > execution. Programs flush their output when they exit, if not before, and shell scripts flush their stdout after each built-in command. > > I am wondering if I need to manually flush the pipe in my C++ code? > and how to do that? Call fflush(). -- Barry Margolin, barmar(a)alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** *** PLEASE don't copy me on replies, I'll read them in the group ***
From: FangQ on 8 Dec 2009 22:53 On Dec 8, 3:42 pm, Barry Margolin <bar...(a)alum.mit.edu> wrote: > Call fflush(). that works! I should have known this. thank you very much
|
Pages: 1 Prev: The regex to capture IPv4 addresses from a file by using (e)grep. Next: unable to open files |