Exetools  

Go Back   Exetools > General > General Discussion

Notices

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 07-09-2011, 23:31
Kerlingen Kerlingen is offline
VIP
 
Join Date: Feb 2011
Posts: 324
Rept. Given: 0
Rept. Rcvd 276 Times in 98 Posts
Thanks Given: 0
Thanks Rcvd at 309 Times in 96 Posts
Kerlingen Reputation: 200-299 Kerlingen Reputation: 200-299 Kerlingen Reputation: 200-299
Flushing input stream

I've a little programming related problem and I don't know how to solve it.

A console program (lets call it "prog1.exe") has the following pseudo-code:
Code:
while not (Ctrl_Break)
{
  x = fetch_stats();     // Read some info
  writeconsole(x);       // Output the info to the console
  wait(60);              // Wait 60 seconds and repeat the whole process
}
I want to log the output of the program both to screen and to a file. So I wrote a little program ("tee.exe") which does:
Code:
while not (EndOfFile(StdIn))
{
  c = read(StdIn);     // Read one char from StdIn
  write(StdOut, c);    // Write one char to StdOut
  write(FILE, c);      // Write the same char to a file
}
In theory, executing "prog1.exe | tee.exe" would redirect all output from "prog1.exe" as input to "tee.exe", while "tee.exe" would write the input it gets to both the console and a file.

The problem is the output buffer. For performance reasons, the OS doesn't write the output of "prog1.exe" to "tee.exe" char-by-char, but waits until the output buffer is full and then writes the whole buffer to "tee.exe". Since "prog1.exe" does only output a few bytes every minute, it takes about 40 minutes before the output buffer is full and transfered to "tee.exe".

Running "prog1.exe >> output.txt" has a similar result: There is no output to the console any more und the file is also only updated when the output buffer is full.

I don't have access to "prog1.exe" or it's source code, so I can't flush the output buffer. Flushing the input buffer is not possible for some reason. The only workarounds I found for the problem describe how to flush the keyboard buffer.

Does anybody have an idea how to solve this problem?

My goal is simple:
1. See the console output in real time
2. Write the console output to a file
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[ARMADILLO] 1 serial & 1 key - need input Maltese General Discussion 2 02-18-2005 00:58


All times are GMT +8. The time now is 10:19.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( 1998 - 2024 )