I have a winforms application that sometimes used from the command line.
Here is the code (simplified of course):
static void Main()
C:\WindowsApplication\start /wait WindowsApplication.exe
Yes. The difference is that cmd.exe is aware of the kind of executable. It knows to wait for the process to terminate when it is a console mode app. It does not wait when it is a regular Windows gui app. Trusting that it will create its own window. So it displays the command prompt again, your output gets appended to that. You'll also have trouble using
You'd have to start your program with
start /wait yourapp.exe to force cmd.exe to wait. Calling
AllocConsole() instead is the only universal fix. Also takes care of creating the console when your app gets started from a shortcut.