2013-05-06 76 views
0

我製作了一個C#控制檯程序,我想在另一個cosole中執行一些批處理。運行另一個cmd

所以,我有主控程序寫在控制檯,並在某個時刻我想在另一個執行批處理。

我知道如何在主控制檯中執行批處理,但我想在另一箇中執行批處理,這是我的問題。

我該如何做到這一點?

編輯: 我用StreaWriter在控制檯這樣寫:

Process process = new Process(); 
ProcessStartInfo startInfo = new ProcessStartInfo(); 
startInfo.FileName = "cmd.exe"; 
startInfo.RedirectStandardInput = true; 
startInfo.UseShellExecute = false; 

process.StartInfo = startInfo; 
process.Start(); 

using (StreamWriter writer = process.StandardInput) 
{ 
    if (writer.BaseStream.CanWrite) 
    { 
     // commands... 
    } 
} 

回答

3

使用的Process.Start:

Process.Start("cmd.exe", "yourcommandhere"); 
+0

我不能這樣做:■ (見我的編輯) – flow 2013-05-07 17:18:41