[英]How to Connect command prompt and Visual Studio 2008?
I am new to C# and I am creating a UI for iperf(windows).我是 C# 的新手,我正在为 iperf(windows) 创建一个 UI。
Since I could not obtain the source code for the windows version, I have to try a different method.由于我无法获得windows版本的源代码,我不得不尝试不同的方法。
My aim is to create a UI which will re-direct the commands to command prompt and get the output and display it back in Visual Studio.我的目标是创建一个 UI,它将命令重定向到命令提示符并获取输出并将其显示回 Visual Studio。
How do I achieve this?我如何实现这一目标?
I suggest you check out the Process
class.我建议您查看
Process
类。 It will allow you to start a new process and redirect the output and error streams.它将允许您启动一个新进程并重定向输出和错误流。
EDIT:编辑:
After reading again it is not clear why you would want to redirect back to Visual Studio.再次阅读后,不清楚为什么要重定向回 Visual Studio。 I initially read this as you want to write a UI that will send commands and display the output using Visual Studio, not actually displaying in Visual Studio.
我最初阅读本文是因为您想编写一个 UI,该 UI 将发送命令并使用 Visual Studio 显示输出,而不是实际显示在 Visual Studio 中。
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "your command here";
p.Start();
p.WaitForExit();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Now output
string variable holds result of command execution.现在
output
字符串变量保存命令执行的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.