Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'd like to edit/create a workspace on the command line without any text editor popping up. The docs say to use the -i flag to use Standard Input. What is the syntax / format of this usage?

Passing a file works correctly: p4 client -i < fileDefiningTheWorkspace.txt

Passing the actual string defining the workspace doesn't work: p4 client -i "Root: C:\The\Root\r\nOptions: noallwrite noclobber....."

Any ideas? Thanks!

like image 808
patrick Avatar asked Dec 11 '12 18:12

patrick


1 Answers

Just entering a string like that won't pass it in standard-input. You need to direct some input, as with your first example of passing a file.

If you really need the string as part of a command line, you would need to use something like echo to pipe the appropriate text in. However echo doesn't support newlines, so you need to echo each line separately:

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

It'll get pretty ugly pretty quickly.

As you seem to be really wanting to know how to do this from c#, here's a very rough and ready example of firing up a command-line process and feeding it 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);
like image 134
JasonD Avatar answered Oct 02 '22 14:10

JasonD