简体   繁体   中英

How to Connect command prompt and Visual Studio 2008?

I am new to C# and I am creating a UI for iperf(windows).

Since I could not obtain the source code for the windows version, I have to try a different method.

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.

How do I achieve this?

I suggest you check out the Process class. 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. 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.

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.

More details here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM