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

Dennis C
  • 23,310
  • 12
  • 68
  • 98

2 Answers2

3

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

Florian Greinacher
  • 13,628
  • 1
  • 31
  • 50
0

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
  • 6,002
  • 1
  • 30
  • 46
  • If the app is built with /target:winexe then Console.Write will *not* normally show up in the console. You can still redirect output to a file though, or pipe it to "more" or another process. Unfortunately "type" doesn't read its stdin, so you can't pipe to it. I can't find a way to redirect to the console though -- seems like ">con" ought to work, but it doesn't. (I'm running Windows 7.) – yoyo Oct 06 '11 at 18:13