Console in Windows Application

P

Pengyu

Hi,

How to add a console window to a Windows application?

Thank you very much in advance,

Pengyu
 
R

Richard Grimes [MVP]

Pengyu said:
Hi,

How to add a console window to a Windows application?

Thank you very much in advance,

Pengyu

What do you want to do with the console window? Do you merely want to
provide a command prompt? If so, then you can do this:

Process.Start("cmd.exe");

If you want to communicate between the command prompt and the .NET GUI
application then you'll have a lot more work to do. Without knowing what you
want to do I cannot say any more.

Richard
 
P

Pengyu Hong

I want my .NET GUI program has a window for Console and can communicate with
the Console.

Thank you very much!

Pengyu
 
A

Ayende Rahien

Do something like this (not tested):
ProccessInfo pi = new ProccessInfo("cmd.exe");
pi.RedirectStandardError=true;
pi.RedirectStandardInput=true;
pi.RedirectStandardOutput=true;
Process cmd = Process.Start(pi);
cmd.StandardInput.WriteLine("Dir");
MessageBox.Show(cmd.StandardOutput.ReadToEnd());

Watch out for deadlocks, those method are blocking!




Pengyu Hong said:
I want my .NET GUI program has a window for Console and can communicate with
the Console.

Thank you very much!

Pengyu
 
V

Vijaye Raji

Try "AttachConsole" API.

-vJ

Pengyu Hong said:
I want my .NET GUI program has a window for Console and can communicate with
the Console.

Thank you very much!

Pengyu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top