How do I open a console from a Winform App?

  • Thread starter Thread starter Frank Rizzo
  • Start date Start date
F

Frank Rizzo

How do I open a console from a Winform App? I've tried
Console.WriteLine but that doesn't work.

Regards
 
hi,

You could start a cmd.exe process.

What is what you want to do exactly?

cheers,
 
Ignacio said:
hi,

You could start a cmd.exe process.

What is what you want to do exactly?

cheers,

I want to print out some debug messages while the process is running
outside the IDE.
 
Look up Log4Net. It can log debug messages to almost anything, you can
change the config file for the level of logging you want while your
application is running, and its free. (http://logging.apache.org/log4net/)

If you really want to open a Console, there are Win32 functions to open them
and what not. Look up AllocConsole, and FreeConsole in MSDN.

An even easier way is to use the www.sysinternals.com tool DebugView with
debugger messages. This also works as a source for Log4Net (see above). The
problem with this is that debug logging only occurs for debug builds. So no
logging in production environment.

Hope this helps...

Chuck
 
hi,

cmd.exe is the MS-DOS command line, it's not the debug console you want.
You have a couple of options, IMO the easier/more convenient one is using
the event log.

cheers,
 
Hi,

You are right :)
More than once I have tried to run cmd.exe on a win9X :)

I don't know the difference though, nor why the two exists.

cheers,
 
Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

You are right :)
More than once I have tried to run cmd.exe on a win9X :)

I don't know the difference though, nor why the two exists.

cmd starts the 32 bit NT OS command interpreter (sometimes mistakenly called
a DOS box), Command runs the 16 bit DOS command interpreter in a ntvdm.

Willy.
 
So, bottom line. Is it possible to open the console from a WinForm app,
just like you would in a console app?

Thanks
 
Sure, you can start the 'cmd' interpreter using Process.Start and redirect
stdout, stdin and stderr to a TextBox control.

Willy.
 
Hi,

I think that the OP want to do the opossite, write in the console window.
If that's so then you can't as the logs will be interpreted as commands.

You can use another form with a listbox for example, or a textbox ( in this
case you have to intercept the KeyPress event ).


cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
 
Ignacio said:
Hi,

I think that the OP want to do the opossite, write in the console window.
If that's so then you can't as the logs will be interpreted as commands.

You can use another form with a listbox for example, or a textbox ( in this
case you have to intercept the KeyPress event ).


cheers,

Thanks, that's exactly what I want to do. So it sounds like I can't do
this or not easily.
 
Hi,

Of course you can do a similar thing, just that you cannot use the cmd.exe
program.
Do as I said, create a new form with a textbox, add a method like
WriteLog( ) that write in the textbox.
Intercept the KeyPress event of the control to allow only the cursor to be
used, all others will be "handled" by your method.


very easy indeed.


cheers,
 
Back
Top