I have an MFC application and launching its .exe from command prompt. What I want to achieve is that I want to show any logs from this launched application on the same command prompt.
I have written this code:
AttachConsole(ATTACH_PARENT_PROCESS);
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), errorMessage, ((string)errorMessage).length(), NULL, NULL);
FreeConsole();
But this code writes the log at the next prompt like this:
c:\Users>application.exe
c:\Users>log line
Here I want the logs on the same prompt, like this:
c:\Users>application.exe
log line
I am stuck with this issue.
The program works just fine; what you see is the command prompt that
cmd.exe
has prepared for you already, because your program detached and ran isolatedly from the console. As long as you don't detach, your program will continously occupy the console window.