Perforce command line: how to use the -i flag in "p4 client -i"?

I would like to edit / create a workspace on the command line without the appearance of a text editor. The docs say using the -i flag to use standard input. What is the syntax / format of this use?

File transfer works correctly: p4 client -i <fileDefiningTheWorkspace.txt

Passing the actual line defining the workspace does not work: p4 client -i "Root: C: \ The \ Root \ r \ nOptions: noallwrite noclobber ....."

Any ideas? Thanks!

+4
source share
2 answers

Just entering a line like this will not go through standard input. You need to direct some input, as in the first file transfer example.

If you really need a line as part of the command line, you will need to use something like echo to include the appropriate text. However, echo does not support newlines, so you need to echo each line separately:

(echo line1 and echo line2 and echo line3) | p4 client -i

It will be pretty ugly pretty fast.

It seems to you that you really want to know how to do this from C #, here is a very crude and ready-made example of starting the command line process and submitting its input:

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); 
+5
source

After I examined this problem in my case, the solution is as follows:

 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(); 

for me it was the same as:

 p4 client - i < clientSpec.txt 
0
source

All Articles