2014-01-23 29 views
0

我想通過Process.Start執行TFS,但我有一些困難,我不明白爲什麼。這裏是我的代碼片段:Process.Start - 與參數TFS命令行掙扎

 /// <summary> 
     /// Get the entire history for a project 
     /// </summary> 
     public void GetHistory(String project) 
     { 
      ProcessStartInfo info = new ProcessStartInfo(); 
      String fileName = Path.GetTempFileName(); 
      info.Arguments = String.Format("history \"{0}\" /recursive /format:Detailed /noprompt > {1}", "c:\\source\\ " + project, fileName); 
      info.FileName = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\Common7\\IDE\\tf.exe\""; 
      info.RedirectStandardError = true; 
      info.UseShellExecute = false; 

      Process process = new Process(); 
      process.StartInfo = info; 
      process.Start(); 

      process.WaitForExit(); 

      Console.WriteLine(process.StandardError.ReadToEnd()); 

      Console.WriteLine("History written to " + fileName); 
      Console.ReadKey(); 
     } 

這導致了一組像這樣的論點(我只是刪除了完整的項目名稱):

enter image description here

然後我得到以下錯誤:

The history command takes exactly one item.

如果我拼湊的字符串,並以正常的命令行執行然而然後它工作:

enter image description here

誰能告訴我我失蹤了什麼?

回答

1

您無法將輸出重定向到Process.Start參數中的文件。文件重定向是shell的一項功能。

如果您想將歷史記錄放入一個文件中,您將需要File.Open自己的文件,請讀取tf history命令的輸出並將其寫入文件。

或者您可以使用命令腳本或PowerShell腳本。