Redirect STD out solved but new problem

Started by
1 comment, last by Nash 19 years, 11 months ago
I finally found a way to redirect the standard out to a pipe. It involved using the SetStdHandle func on the handle returned from CreateFile when I connected to the pipe. However I have a new problem. When I set the buffer to zero (setvbuf), my printf statements send one character at a time to my pipe server app. When I set a defined buffer size (lets say 1024), the characters aren''t sent until either I have a full 1024 or I call flush(stdout). I could call define a large buffer and call the flush func after each printf, but it would defeat the whole idea. I wanted to change as little as possible on the original app. Is there a way to make the buffer flush after each printf without flush? Or must I change the way I read the pipe on the server side (alter the way I call ReadFile maybe)? Thanks
Advertisement
The ugly hack: Set up a timer to flush the pipe every 10th/30th/100th of a second.
The nice way: I''m too lazy to look up, but it probably exists.
#define PRINTF(bla) printf(bla);\
/*flush, however you like to*/;

This topic is closed to new replies.

Advertisement