2012-12-11 78 views
4

我想在命令行上編輯/創建一個工作區,而不用彈出任何文本編輯器。文檔說使用-i標誌來使用標準輸入。這種用法的語法/格式是什麼?Perforce命令行:如何在「p4 client -i」中使用-i標誌?

傳遞一個文件正常工作: P4客戶-i < fileDefiningTheWorkspace.txt

傳遞定義工作區的實際字符串不起作用: P4客戶-i「根:C:\中\ ROOT \ r \ n選項:noallwrite noclobber .....「

任何想法? 謝謝!

+0

高興ÿ你問這個問題。謝謝! – asgs

回答

5

只需輸入一個像這樣的字符串將不會通過標準輸入。您需要指導一些輸入,就像您傳遞文件的第一個示例一樣。

如果你確實需要字符串作爲命令行的一部分,你需要使用類似echo的東西來管理合適的文本。但是echo不支持換行符,所以你需要分別回顯每一行:

(回波線1 &回波線2 &回波線3) p4客戶端-i

它會很快變得非常難看。

正如你似乎是真的想知道如何從C#做到這一點,這裏的發射了一個命令行程序和餵養它的輸入非常粗糙和現成的例子:

 ProcessStartInfo s_info = new ProcessStartInfo(@"sort.exe"); 
     s_info.RedirectStandardInput = true; 
     s_info.RedirectStandardOutput = true; 
     s_info.UseShellExecute = false; 
     Process proc = new Process(); 
     proc.StartInfo = s_info; 
     proc.Start(); 
     proc.StandardInput.WriteLine("123"); 
     proc.StandardInput.WriteLine("abc"); 
     proc.StandardInput.WriteLine("456"); 
     proc.StandardInput.Close(); 
     String output = proc.StandardOutput.ReadToEnd(); 
     System.Console.Write(output); 
+0

您可以使用here文檔。 Bash在這裏也有'<<<'你的信息''。 – tripleee

+0

感謝您的回答。我的最終目標是在c#中執行此操作,方法是在字符串中創建工作區詳細信息,並將其傳遞給要運行的過程。我可以暫時將文件寫入磁盤,然後像上面那樣使用該文件(p4 client -i patrick

+1

從C#開始,爲什麼不直接使用API​​呢? – JasonD

0

我」後VE處理了我的情況下解決這個問題似乎是這樣的:

P4Process.StartInfo.Arguments="client -i" 
StreamWriter myStreamWriter = P4Process.StandardInput; 
       String inputText = File.ReadAllText(@"C:\Program Files\Perforce\clientSpec.txt"); 
       myStreamWriter.Write(inputText); 
       P4Process.StandardInput.Close();     

       P4Process.BeginOutputReadLine(); 
       P4Process.BeginErrorReadLine(); 

       P4Process.WaitForExit(); 

對我來說是一樣的:

p4 client - i < clientSpec.txt 
相關問題