Pelles C forum

C language => Windows questions => Topic started by: JohnF on December 09, 2008, 11:02:45 AM

Title: Stop console window from closing ?
Post by: JohnF on December 09, 2008, 11:02:45 AM
I don't know if this has been discussed before - is there a way to stop a console window from closing - like an IDE does it?

The console app is a third party program that finishes and closes before the output can be read.

Using for example ShellExecute().

Ta!

John
Title: Re: Stop console window from closing ?
Post by: Vortex on December 09, 2008, 11:53:17 AM
Hi John,

Why not to launch the console application from the command prompt?
Title: Re: Stop console window from closing ?
Post by: JohnF on December 09, 2008, 12:24:12 PM
Quote from: Vortex on December 09, 2008, 11:53:17 AM
Hi John,

Why not to launch the console application from the command prompt?

Vortex,

Well, it just isn't going to be started that way.

However as a matter of interest if it was started from the command prompt, is there a way to stop it closing its window?

John
Title: Re: Stop console window from closing ?
Post by: Stefan Pendl on December 09, 2008, 12:24:37 PM
Use CMD /K to launch it.
Title: Re: Stop console window from closing ?
Post by: Vortex on December 09, 2008, 12:32:07 PM
Hi John,

Maybe, you can try to hook the ExitProcess function to stop the console windows from closing.
Title: Re: Stop console window from closing ?
Post by: JohnF on December 09, 2008, 01:24:19 PM
Quote from: Stefan Pendl on December 09, 2008, 12:24:37 PM
Use CMD /K to launch it.


Thanks, that works.

John
Title: Re: Stop console window from closing ?
Post by: JohnF on December 09, 2008, 01:25:15 PM
Quote from: Vortex on December 09, 2008, 12:32:07 PM
Hi John,

Maybe, you can try to hook the ExitProcess function to stop the console windows from closing.

Yes, I was looking for an easier way, see above.

Thanks.

John
Title: Re: Stop console window from closing ?
Post by: JohnF on December 09, 2008, 01:33:12 PM
Quote from: JohnF on December 09, 2008, 01:24:19 PM
Quote from: Stefan Pendl on December 09, 2008, 12:24:37 PM
Use CMD /K to launch it.


Thanks, that works from the command line but not when using ShellExecute.

John

Title: Re: Stop console window from closing ?
Post by: JohnF on December 09, 2008, 01:43:36 PM
Quote from: JohnF on December 09, 2008, 01:24:19 PM
Quote from: Stefan Pendl on December 09, 2008, 12:24:37 PM
Use CMD /K to launch it.


Thanks, that works with WinExec().

John

Title: Re: Stop console window from closing ?
Post by: blzbb on December 10, 2008, 09:51:31 AM
another way could be using CreateProcess and use pause command in lpCommandLine like this


CreateProcess(NULL, "program.exe | pause", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
WaitForSingleObject(pi.hProcess, INFINITE);
Title: Re: Stop console window from closing ?
Post by: JohnF on December 10, 2008, 11:29:45 AM
Quote from: blzbb on December 10, 2008, 09:51:31 AM
another way could be using CreateProcess and use pause command in lpCommandLine like this


CreateProcess(NULL, "program.exe | pause", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
WaitForSingleObject(pi.hProcess, INFINITE);


Ok, thank you.

John