views:

462

answers:

2

I have a C# project building "winexe" that startup without console window.

However, I want to dispaly the console window and write stdout/stderr by giving a cmd line parameter. If it close, the application shutdown. For example: eclipse.exe -debug

How can it be done?

PS. I am using Visual Studio 2005

A: 

Even in a Windows Forms application the console is there and you can start writing using System.Console, possibly based on a commandline option like you mention, or a configuration switch, or whatever. Starting your application from a console window prompt will open your GUI like normal and the console output will be shown in the console like you expect. You can even still redirect that console output to a file for instance. Maybe that's enough for you?

Actually starting to show a console window from your Windows Forms application is something else. Not completely sure how to do it (if even possible). I'd look into starting a cmd instance, possibly using System.Diagnostics.Process to start a process while redirecting stdin/stdout/stderr of that new process?

This is just speculation on my part at the moment though. Maybe some of the other answers will help here?

peSHIr
+3  A: 

Tried this: http://vaibhavgaikwad.wordpress.com/2007/02/21/console-window-for-a-windows-application-in-net/ - seems to works perfectly!

m0rb