打开进程后启动命令提示符如何在c#中编写ipconfig

Soh*_*ail 3 c# console-application

我从c#打开命令提示符

 Process.Start("cmd");
Run Code Online (Sandbox Code Playgroud)

当它打开时我需要自动编写ipconfig,这样进程打开并找到工作站的ip,我该怎么做?

Pra*_*ana 5

编辑

Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "ipconfig.exe";
p.Start();
p.WaitForExit();
string output = p.StandardOutput.ReadToEnd();
return output;
Run Code Online (Sandbox Code Playgroud)

要么

编辑

  Process pr = new Process();
  pr.StartInfo.FileName = "cmd.exe";
  pr.StartInfo.Arguments = "/k ipconfig"; 
  pr.Start();
Run Code Online (Sandbox Code Playgroud)

检查:如何在C#中执行命令?

System.Diagnostics.Process process = new System.Diagnostics.Process(); 
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
 startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
 startInfo.FileName = "cmd.exe";
 startInfo.Arguments = "ipconfig";
 process.StartInfo = startInfo;
 process.Start(); 
Run Code Online (Sandbox Code Playgroud)

要么