I have an executable file which prints “Hello World”; File name “PrintOutput.exe”.
I have to get the console output that is “Hello World” in C++ project. How will I do that?
int _tmain(int argc, _TCHAR* argv[])
{
char psBuffer[128];
FILE *pPipe;
pPipe = _popen( “PrintOutput.exe”, “rt” );
if (NULL == pPipe)
{
printf(“error input”);
return 0;
}
while(NULL != fgets(psBuffer, 128, pPipe))
{
printf(psBuffer); // print the console output of “PrintOutput.exe”
}
_pclose( pPipe );
}