Hi, first off, this might be platform-dependant, and if so, I need it to work in windows - what I need it for already works in linux, so...

ok, here's the background... I wrote (as have many others during the last many years) a console-based program that uses ansi escape sequences for prettying up the output, and that's just great - except that windows stopped supporting it in >=NT, and though hacks seem to be able to make NT support it, I've found nothing to re-enable it in XP

I proceded to write a wrapper program, that could be used like so: app | wrapper; making any app using the sequences able to function in XP too (the wrapper simply translates the sequences into approprate windows function-calls)*

as it happens, my program, and (I would assume) most others written as console-applications, don't explicitly fflush stdout all that often, simply because it isn't needed in a linebuffered environment - stuff like printing \n or calling getchar() (especially the latter creates a problem) will automatically flush it for you...

the problem is, that when I pipe the output to my wrapper, the original programs stdout becomes block buffered by default - (then the user probably won't see any output till the app exits, and that's a problem when you require him to input data) in the case of my program, I can easily change that, but I'd like to be able to run any legacy application through my wrapper...

that said, it seems to me that what I need is either some fancy trick to make the original program run with a linebuffered stdout, or - something in the region of (in posix-terminology) in the simplest form, creating a(nother?) wrapper that forks, execv()'s the original application, and then either somehow from the parent sets the child pid's stdout to linebuffered (setlinebuf()), or having the childs stdout point to a buffer in the parent which is under local control...

I'm open to alternaive suggestions, but those two were the ones I found most probable as solutions
Any ideas how I could possibly achieve this?

Thanks in advance, Christian Sonne

*=and no, it's not a complete implementation, but most of it works... :-)

PS: if code-examples for a simple wrapper, and a simple app that demonstrates the problem would be usefull, I'll gladly submit that - they're both trivial, so for now I'll leave them out, so this post doesn't get even longer...