VS 2013 C++ console app logs console output but the same code does not work with VS 2019.

  • Thread starter Thread starter player55328
  • Start date Start date
P

player55328

Guest
I recently upgraded a large project from 2013 to 2019. It turns out the feature to log the console output stopped working. To make sure it was not some of the changes I had to do to make 2019 happy I rebuilt the updated code with 2013 and the feature still works. This feature is able to be started and stopped in the 2013 code but in the 2019 code the call to ReadFile() in the below code never returns. Any suggestions on how to make this work in 2019? Sorry for the formatting, cut and paste does not seem to work here very well.

Part of the thread while logging is active...







HANDLEhReadPipe;



HANDLEhWritePipe;



BOOLsuccess = CreatePipe(&hReadPipe, &hWritePipe, NULL, 0);



if(!success)

{

printf("logConsoleThread CreatePipe() failed...\n");



fprintf(_logConsoleStream,"\nlogConsoleThread CreatePipe() failed...");


fflush(_logConsoleStream);




delete[]_logConsoleFilename;


_logConsoleFilename = NULL;





return;


}






FILEoriginalStdout = *stdout;



intstream = _open_osfhandle(intptr_t(hWritePipe), _O_TEXT); // 0 means _O_TEXT



if(stream == -1)


{

printf("logConsoleThread _open_osfhandle() failed...\n");


fprintf(_logConsoleStream,"\nlogConsoleThread _open_osfhandle() failed...");


fflush(_logConsoleStream);




delete[]_logConsoleFilename;


_logConsoleFilename = NULL;




return;


}




FILE* file = _fdopen(stream, "wt");



// Disable buffering.


setvbuf(file, NULL, _IONBF, 0);


fflush(stdout);


*stdout=*file;




while(!_logConsoleAbort)


{




DWORDnumRead;



charbuf[READPIPE_MAXCHARS + 1]; // Hold the Console Msg



BOOLsuccess = ReadFile(hReadPipe, buf, READPIPE_MAXCHARS, &numRead, NULL);


// Output buf to console (cerr) and log file...


Continue reading...
 
Back
Top