Hello everybody, this is my first post here. I'm been scouring the internets trying to find a solution to my problem. I have an MFC application, and I would like to be able to read stdout into a buffer so that I can do things with the output. The reason being, I am linking to libs that use stdout to print debug information, and I have no way of controlling where those libs write. So, I've tried the whole CreatePipe, SetSTDHandle, thing, but I get a stall when I go to ReadFile on the stream. My code looks something like:
HANDLE read;
HANDLE write;
CreatePipe(&read, &write, 0, 8192);
bool b = SetStdHandle( STD_OUTPUT_HANDLE, write );
b = SetStdHandle( STD_ERROR_HANDLE, write );
printf("ceci n'est pas une pipe");
printf("and more!");
fflush(stdout);
FlushFileBuffers(read);
FlushFileBuffers(write);
DWORD bytes_read;
b = ReadFile(read, buffer, 1000, &bytes_read, NULL );
Everything seem to be returning true except when it comes to the ReadFile. The app will just hang there forever and never return. Anyone know how to get around this or what's going on?
Yes, ReadFile is a blocking function. It doesn't return unless there is an error, or the specified number of bytes have been read (or, if you use it asynchronously; I believe that has to do with overlapped I/O).
Viggy
Last edited by MrViggy; June 21st, 2010 at 11:50 AM.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.