效果图
主要代码方法
private Process p;
public List<string> ExecuteCmd(string args)
{
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.StandardOutputEncoding = System.Text.Encoding.UTF8;
//p.StartInfo.StandardErrorEncoding = System.Text.Encoding.UTF8;
p.Start();
p.StandardInput.WriteLine(args + "&exit");
p.StandardInput.AutoFlush = true;
//p.StandardInput.WriteLine("exit");
var list = new List<string>();
StreamReader reader = p.StandardOutput;
string line = reader.ReadLine();
while (!reader.EndOfStream)
{
list.Add(line);
line = reader.ReadLine();
}
p.WaitForExit();
p.Close();
return list;
}