NO

Author Topic: Stop console window from closing ?  (Read 12267 times)

JohnF

  • Guest
Stop console window from closing ?
« 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
« Last Edit: December 09, 2008, 11:06:22 AM by JohnF »

Offline Vortex

  • Member
  • *
  • Posts: 865
    • http://www.vortex.masmcode.com
Re: Stop console window from closing ?
« Reply #1 on: December 09, 2008, 11:53:17 AM »
Hi John,

Why not to launch the console application from the command prompt?
Code it... That's all...

JohnF

  • Guest
Re: Stop console window from closing ?
« Reply #2 on: December 09, 2008, 12:24:12 PM »
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

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: Stop console window from closing ?
« Reply #3 on: December 09, 2008, 12:24:37 PM »
Use CMD /K to launch it.
---
Stefan

Proud member of the UltraDefrag Development Team

Offline Vortex

  • Member
  • *
  • Posts: 865
    • http://www.vortex.masmcode.com
Re: Stop console window from closing ?
« Reply #4 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.
« Last Edit: December 09, 2008, 12:33:40 PM by Vortex »
Code it... That's all...

JohnF

  • Guest
Re: Stop console window from closing ?
« Reply #5 on: December 09, 2008, 01:24:19 PM »
Use CMD /K to launch it.


Thanks, that works.

John

JohnF

  • Guest
Re: Stop console window from closing ?
« Reply #6 on: December 09, 2008, 01:25:15 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

JohnF

  • Guest
Re: Stop console window from closing ?
« Reply #7 on: December 09, 2008, 01:33:12 PM »
Use CMD /K to launch it.


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

John


JohnF

  • Guest
Re: Stop console window from closing ?
« Reply #8 on: December 09, 2008, 01:43:36 PM »

blzbb

  • Guest
Re: Stop console window from closing ?
« Reply #9 on: December 10, 2008, 09:51:31 AM »
another way could be using CreateProcess and use pause command in lpCommandLine like this

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

JohnF

  • Guest
Re: Stop console window from closing ?
« Reply #10 on: December 10, 2008, 11:29:45 AM »
another way could be using CreateProcess and use pause command in lpCommandLine like this

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

Ok, thank you.

John