简体   繁体   English

如何连接命令提示符和 Visual Studio 2008?

[英]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字符串变量保存命令执行的结果。

More details here更多细节在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Visual Studio工具栏在命令提示窗口上运行控制台应用程序 - How to run console application on command prompt window with visual studio Toolbar Visual Studio 2015 命令提示符问题 - Visual Studio 2015 Command Prompt issues 将参数发送到Visual Studio的开发人员命令提示符 - Sending arguments to Developer Command Prompt for Visual Studio Visual Studio 2008无法连接到SQL Server 2008 - Visual Studio 2008 doesn't connect to SQL Server 2008 Visual Studio 外部工具向命令提示符发送命令 - Visual Studio External Tools sending command to command prompt 运行命令提示符命令以在Visual Studio中启动解决方案 - run a command prompt command to start a solution in Visual Studio 如何使用Visual Studio 2017中编译的C#应用​​程序连接到SQL Server 2008? - How to connect to SQL Server 2008 with C# application compiled in Visual Studio 2017? 如何在Visual Studio输出窗口中运行控制台应用程序,而不是打开新的命令提示符? - How do you run a console application in the Visual Studio output window, instead of opening a new command prompt? 在Visual Studio命令提示符2010中构建c#dll时如何指定.net目标框架? - How to specify .net target framework when building c# dll in Visual Studio Command Prompt 2010? 如何将VS命令提示符添加到Visual Studio 2010 C#Express? - How can I add the VS Command Prompt to Visual Studio 2010 C# Express?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM