Keeping the console window open after game closes for debugging

Started by
5 comments, last by SiCrane 11 years, 10 months ago
I'm using a console window for debugging purposes in my program, and i want the console window to stay open after i close the window,


int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrev,char * szCmdLine,int nCmdShow)
{
std::cout << "Initializing...\n";
program->Initialize();

std::cout << "Running...\n";
program->Run();

std::cout << "Shutting Down...\n";
program->Shutdown();

return 0;
}

int main(void)
{
WinMain(GetModuleHandle(NULL), NULL,
nullptr, SW_SHOWDEFAULT);

system("PAUSE");
return 0;
}

// With this setup, when i close the window it still stays open but it's frozen, but the cmd window stays open and works properly
/** I want the window to close completly but then the console window stays open **/
// And also im using "vld" (Visual Leak Detector), and it outputs it's status to the cmd window after the program closes completely, so i only get // to see it for a split second before the cmd window closes. Is there a way to pause it after the "vld" shows it's status?
Advertisement
One thing to try would be to spawn a child console process that would wait for input before it closes.
If you get to the point that the program pauses at the end from the pause-command without the window closing, then I would guess that you haven't closed it properly in your code in the first place. I would fix that first. but I would advice against forcing the console to stay open programatically if you can anyway. For example, if you're using Visual Studio, run the program with Ctrl-F5 and it will keep the console open after the program exits.

One thing to try would be to spawn a child console process that would wait for input before it closes.

that's pretty much what i'm doing... lol


If you get to the point that the program pauses at the end from the pause-command without the window closing, then I would guess that you haven't closed it properly in your code in the first place. I would fix that first. but I would advice against forcing the console to stay open programatically if you can anyway. For example, if you're using Visual Studio, run the program with Ctrl-F5 and it will keep the console open after the program exits.

oh yeah i forgot about ctrl+F5 lol, havent used console windows in a while lol. But yeah, you might be right i'll check my code for closing the window and see what might be wrong there

that's pretty much what i'm doing... lol

Yeah, but the silly part is having your program wait for the spawned process to close before closing itself.
i did that because i couldn't get it to stay open, i'm trying to see the results after the program shuts down.
Yes, I know. But a system() call waits for the spawned process to close before the calling process closes, which does nothing for keeping the console window open after the calling process closes. You'd want the spawned process to exist after the calling process closes, which would involve a function like CreateProcess() or something similar.

This topic is closed to new replies.

Advertisement