【转】C#创建进程并执行

 1 string RunCommand(string command)
 2 {
 3   Process myProcess = new Process();
 4   myProcess.StartInfo.FileName = "cmd.exe";
 5   myProcess.StartInfo.UseShellExecute = false;
 6   myProcess.StartInfo.RedirectStandardInput = true;
 7   myProcess.StartInfo.RedirectStandardOutput = true;
 8   myProcess.StartInfo.RedirectStandardError = true;
 9   myProcess.StartInfo.CreateNoWindow = true;
10   myProcess.Start();
11   myProcess.StandardInput.WriteLine(command);
12   myProcess.StandardInput.WriteLine("exit");
13   myProcess.WaitForExit();
14 
15   return myProcess.StandardOutput.ReadToEnd();
16 }

 

posted @ 2018-03-31 15:49  死鱼眼の猫  阅读(1133)  评论(0编辑  收藏  举报