close

                var process = new Process
                {
                    StartInfo = new ProcessStartInfo
                    {
                       FileName = "C:\\Debug\\ConsoleTest.exe",                    // 執行檔路徑
                        Arguments = "",                                                              // 執行時傳入的引數
                        UseShellExecute = false,                                                 // 表示是否要使用作業系統 shell 來啟動處理程序
                        CreateNoWindow = false,                                               // 表示是否要在新視窗中啟動處理程序
                        WindowStyle = ProcessWindowStyle.Hidden,                // 表示新視窗的顯示方式
                        RedirectStandardOutput = true,                                     // 表示應用程式的文字輸出是否寫入至 StandardOutput 資料流
                        RedirectStandardError = true,                                         // 表示應用程式的錯誤輸出是否寫入至 StandardError 資料流
                    },
                };
                //process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
                //process.ErrorDataReceived += new DataReceivedEventHandler(OutputHandler);
                
                process.Start();
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();
                process.WaitForExit();

                 static void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
                 {
                     // Write to console
                     Console.WriteLine(outLine.Data);
                 }

arrow
arrow
    文章標籤
    Asp.Net C#
    全站熱搜
    創作者介紹
    創作者 芭樂養樂多 的頭像
    芭樂養樂多

    隨手筆記

    芭樂養樂多 發表在 痞客邦 留言(0) 人氣()