Reputation: 7128
I am developing an application that writes some exception messages to the Console
if they are of no use to the user. As a result if someone runs the executable by simply double clicking it, they will never see these messages.
In Visual Studio these messages show up in the output window, but in my case I am testing my application on a machine that does not a Visual Studio installation, though I still want to see if any of these messages appear.
In the past I have simply ran the executable from the command prompt and it acted as the output window in Visual Studio. Though for some reason my application, when ran from the command prompt, simple "returns" and does not show any messages.
For example I might start it like so, and it instantly returns
D:\>MyApp.exe
D:\>
I am not sure if there is a specific switch I should use (I have tried /K
to no avail) when I run it, or if there is something about my application that causes it to return.
Any ideas on how I might run it via the command line so I can see the messages?
For reference here is my applications Program.cs
static class Program
{
static Mutex mutex = new Mutex(true, "{12345678-1234-1234-1234-123456789012}");
[STAThread]
static void Main()
{
if (mutex.WaitOne(TimeSpan.Zero, true))
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
SplashScreen.ShowSplashScreen();
Application.Run(MainForm.Instance);
mutex.ReleaseMutex();
}
else
NativeMethods.PostMessage((IntPtr)NativeMethods.HWND_BROADCAST, NativeMethods.WM_JTTMAINWINDOW, IntPtr.Zero, IntPtr.Zero);
}
}
Upvotes: 1
Views: 643
Reputation: 36308
To allow your program to output to the console, build it as a console application.
In Visual Studio, the relevant linker option is /SUBSYSTEM:Console
; or, when creating a new project, choose the "console application" template which will set the linker option automatically.
This will also mean that if you run the program from the command prompt, the command prompt will wait for the program to exit. Also, if you double-click the program rather than running it from the command prompt, a console window will automatically be created.
(There is no way to make the command prompt wait for a program but prevent the program from creating a console window if double-clicked. See this question and its answers for more information.)
Upvotes: 1