日期:2014-05-18 浏览次数:20783 次
static void Main(string[] args) { string output; using (System.Diagnostics.Process p = new System.Diagnostics.Process()) { p.StartInfo.FileName = "cmd.exe"; p.StartInfo.Arguments= "/c dir"; p.StartInfo.CreateNoWindow = true; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.Start(); output = p.StandardOutput.ReadToEnd(); Console.WriteLine(output); p.StandardInput.WriteLine("exit"); p.StandardInput.WriteLine("ping 127.0.0.1"); p.StandardInput.WriteLine("exit"); output = p.StandardOutput.ReadToEnd(); Console.WriteLine(output); p.WaitForExit(); } }