开发者

C# can I add the command prompt control to my app

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 defi开发者_运维知识库nitely help.


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜