I am trying to create a string to pass to cmd to have P4V create and label a file. The problem is the when I pass the string to cmd the escape \ is seen as part of the file path and causing the file not to be found. Is there a way to pass a " without the \ ?
Here is the code I am using it generates a string in cmd as
p4 tag -l labelname \"c:\folder\filename\"
P4 needs the quotes outside the string.
Needed:
p4 tag -l labelname "c:\folder\filename"
string tempString = @" """;
tempString = tempString + stringToTest;
stringToTest = tempString + @" """;
System.Diagnostics.ProcessStartInfo proc = new System.Diagnostics.ProcessStartInfo();
proc.FileName = @"c:\windows\system32\cmd.exe";
proc.Arguments = @"/k p4 tag -l " + newLabel + " " + stringToTest;
System.Diagnostics.Process.Start(proc);}enter code here
Any help appreciated.
Here the actual string that is passed to the process (proc.Arguments). I don't have Perforce on this machine so I can't show what is in cmd.exe.
"/k p4 tag -l labelname \"c:\folder\filename \""
I find it a lot clearer when you compose strings using String.Format
proc.Arguments = string.Format("/k p4 tag -l {0} \"{1}\"",
"labelName",
@"c:\folder\filename");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With