Jump to content
  • Advertisement
Sign in to follow this  
Muzzy A

Keeping the console window open after game closes for debugging

This topic is 2185 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?
Edited by Muzzy A

Share this post


Link to post
Share on other sites
Advertisement
One thing to try would be to spawn a child console process that would wait for input before it closes.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
i did that because i couldn't get it to stay open, i'm trying to see the results after the program shuts down.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!