using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; using System.Threading; namespace ReNewCert { class Program { static void Main(string[] args) { Process p = new Process(); //設置要啟動的應用程序 p.StartInfo.FileName = "C:\\Desktop\\wacs.exe";//是否使用操作系統shell啟動 p.StartInfo.UseShellExecute = false; // 接受來自調用程序的輸入信息 p.StartInfo.RedirectStandardInput = true; //輸出信息 p.StartInfo.RedirectStandardOutput = true; // 輸出錯誤 p.StartInfo.RedirectStandardError = true; //不顯示程序窗口 p.StartInfo.CreateNoWindow = true ; //啟動程序 p.Start(); Thread.Sleep(5000); //向cmd窗口發送輸入信息 p.StandardInput.WriteLine("R"); p.StandardInput.WriteLine("exit"); p.StandardInput.AutoFlush =true ; Thread.Sleep(5000); p.StandardInput.WriteLine("Q"); p.StandardInput.WriteLine("exit"); string strOuput = p.StandardOutput.ReadToEnd(); //等待程序執行完退出進程 p.WaitForExit(); p.Close(); Console.WriteLine(strOuput); } } }