2011-06-17 31 views
-3

我有代碼,啓動一個程序:C# - 使用開關啓動時過程

Process.Start("cmd.exe", "/c test.exe \"\" > output.txt").WaitForExit(); 

雖然不是我想用一個參數/交換機的test.exe:

test.exe -F input.txt 

怎麼可能這樣做?

+0

我想你需要更詳細地查看'Process'和'ProcessStartInfo'類的文檔。你的使用表明你還沒有這樣做;你不需要運行'cmd.exe',你不需要重定向你正在運行的命令的輸出。 'Process'和'ProcessStartInfo'可以爲你處理所有這些。 –

+0

可能的重複[C# - Process.Start - 使用參數](http://stackoverflow.com/questions/6392409/c-process-start-using-parameters-with-it) – M4N

回答

3

使用ProcessStartInfo.Arguments。在msdn頁面中有一個例子。

var process = new Process 
         { 
          StartInfo = new ProcessStartInfo 
              { 
               FileName = "test.exe", 
               Arguments = "-F input.txt", 
              } 
         }; 
    process.Start(); 
    process.WaitForExit(); 
+0

我將如何做輸出雖然? (output.txt)? – Michael

+0

@Michael你不能'Process.Start(「cmd.exe」,@「/ c test.exe -f input.txt> output.txt」)。WaitForExit();'? –

+0

是的,是的,我可以:)謝謝 – Michael