2010-06-18 61 views

回答

6

我不知道你是否會找到一個直接的例子,但它不是太困難。我沒有時間爲你寫的所有代碼,但我可以給你從MSDN代碼:

Process myProcess = new Process(); 

ProcessStartInfo myProcessStartInfo = 
    new ProcessStartInfo("C:\\MyBatchFile.bat"); 
myProcessStartInfo.UseShellExecute = false; 
myProcessStartInfo.RedirectStandardOutput = true; 

myProcess.StartInfo = myProcessStartInfo; 
myProcess.Start(); 

StreamReader myStreamReader = myProcess.StandardOutput; 

// Read the standard output of the spawned process. 
string myString = myStreamReader.ReadToEnd(); 

myProcess.Close(); 

// Now you have the output of the batch file in myString 
+0

我會建議'myStreamReader.ReadToEnd();',但堅實的+1。 ;) – Lance 2010-06-18 15:30:15

+0

@ Lance May - 我希望在發佈前做出更改。這是MSDN最初使用的。我做了更新。 – 2010-06-18 15:35:21

1

看到這個answer這裏。

它會告訴你如何將輸出重定向到一個事件。然後,您可以拿出輸出並將其放入您的雙贏控制中。

相關問題