这个算是一个文章
执行指定的Cmd命令,并获取执行结果
Code
1 using System.Diagnostics;
2
3 /**//// <summary>
4 /// 启动Cmd并执行指定的命令,并返回执行的结果
5 /// </summary>
6 /// <param name="strCommand">命令文件</param>
7 /// <returns>执行结果</returns>
8 private string ShellStart(string strCommand)
9 {
10 ProcessStartInfo psi = new ProcessStartInfo("cmd");
11 psi.Arguments = "/c " + strCommand;
12 psi.RedirectStandardInput = true;
13 psi.RedirectStandardOutput = true;
14 psi.CreateNoWindow = true;
15 psi.UseShellExecute = false;
16 Process p = new Process();
17 p.StartInfo = psi;
18 p.Start();
19 return p.StandardOutput.ReadToEnd();
20 }
1 using System.Diagnostics;
2
3 /**//// <summary>
4 /// 启动Cmd并执行指定的命令,并返回执行的结果
5 /// </summary>
6 /// <param name="strCommand">命令文件</param>
7 /// <returns>执行结果</returns>
8 private string ShellStart(string strCommand)
9 {
10 ProcessStartInfo psi = new ProcessStartInfo("cmd");
11 psi.Arguments = "/c " + strCommand;
12 psi.RedirectStandardInput = true;
13 psi.RedirectStandardOutput = true;
14 psi.CreateNoWindow = true;
15 psi.UseShellExecute = false;
16 Process p = new Process();
17 p.StartInfo = psi;
18 p.Start();
19 return p.StandardOutput.ReadToEnd();
20 }