tags:

views:

315

answers:

3

I have a progaram that can be ran both as a winform, or from command line. If it is invoked from a command line I call AttachConsole(-1) to attach to parent console.

However, after my program ends, the user must hit enter to get back the standard command prompt ("c:\>"). is there a way to avoid that need?

Thanks. I could wrap it in a cmd file to avoid that issue, but I would like to do it from my exe.

A: 

Try calling the FreeConsole function prior to exiting your executable.

Nick
I've already tried that, doesn't seem to work. thanks anyway.
Clangon
+2  A: 

Try adding this line just before your exe exits...

System.Windows.Forms.SendKeys.SendWait("{ENTER}");

Bit of a hack, but best I could find when I encountered that problem.

Rob

Rob L
It worked, thanks.
Clangon
A: 

Ok, I don't have the solution, but it seems to be because the cmd.exe is not waiting on the started process, whereas with a normal console application cmd.exe waits until the the application exits. I don't know what makes cmd.exe decide to wait or not on an application, normal Windows Forms applications are just started and cmd.exe doesn't wait for it to exit. Maybe this hint triggers somebody! I will dig a bit deeper in the mean while.

Wout

Wout