tags:

views:

58

answers:

3

Title says it. I know I can use Process or ProcessStartInfo to run arguments, but I mean actually adding a command prompt control to my app (because I use it very often and it'd be convenient if it was already built-in.

Is there any way to do this other than coding a custom control? If not I can live with it, but it would definitely help.

+1  A: 

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");
textBox1.Text = cmd.StandardOutput.ReadToEnd();

Watch out for deadlocks, those method can be blocking!

You can also use this solution from codeproject.com: http://www.codeproject.com/KB/miscctrl/commandprompt.aspx

Peter van Kekem
A: 

See this question and related. Also this source code for example.

You can start a console near your win app's window which you will control and can output some data or get input from a user.

abatishchev
I don't quit get it. Using AllocConsole() I can attach a console control to my application? But how does it work and how can I use it?
david
@david: `AllocConsole()` creates a console window near your main form and you can write their using standard `Console.WriteLine()`
abatishchev
Alright, thanks for the info ;)
david
@david: Please try and if it works, accept my answer as correct ;)
abatishchev
I'm a bit busy right now but I will try the solution soon and accept your answer if it works :)
david
@david: Sounds good :)
abatishchev
@david: Glad it helped! Vote up a bit please :)
abatishchev
A: 

What is the problem with doing Console.ReadLine()/Console.WriteLine() in a loop? It is the most efficient way and you have fully control over what you are doing.

codymanix
Who voted my answer down? I consider this functionality trivial, why use other libraries which may cause problems and add dependencies (cmd.exe only works on windows, you can only execute other executables when having full trust).
codymanix
Could you elaborate on it?
david
*rofl* I got an accepted -1 answer. Isn't there a special badge for this?
codymanix