[英]How can I retrieve the P4 ROOT variable value in a Windows Batch file?
I want to retrieve the p4 CLIENT ROOT variable that appears in p4 info but not sure how. 我想检索p4信息中出现但不确定如何的p4 CLIENT ROOT变量。 I am new to batch scripts myself. 我自己是批处理脚本的新手。 I've taken a look at http://answers.perforce.com/articles/KB_Article/Accessing-Perforce-Environment-Variables-From-a-Windows-Batch-File but I changed CLIENT to ROOT but it doesn't seem to work. 我已经看过http://answers.perforce.com/articles/KB_Article/Accessing-Perforce-Environment-Variables-From-a-Windows-Batch-File但是我将CLIENT更改为ROOT但似乎没有上班。
EDIT: I've found a way to make the commands in that tutorial to work but that defeats the purpose of what I am trying to achieve because I have to manually set P4ROOT in the command line. 编辑:我已经找到了一种方法来使该教程中的命令工作,但这违背了我想要实现的目的,因为我必须在命令行中手动设置P4ROOT。 Instead I am assuming I don't know the root folder so I want to find it from p4 info somehow. 相反,我假设我不知道根文件夹,所以我想以某种方式从p4信息中找到它。
As Bryan noted, the client root and the server root are two different things, and it's good to be clear on which one it is you're trying to get (it sounds like you want to get the client root for the current client; this is set in the client spec and not in any environment variable on either the client or server side). 正如Bryan所说,客户端root和服务器根是两个不同的东西,很清楚你想要获得哪一个(听起来你想要为当前客户端获取客户端root;这个在客户端规范中设置,而不是在客户端或服务器端的任何环境变量中设置)。 You can get them both from the output of "p4 info", though, and you can use the -F global option to p4 to isolate either field with minimal fuss: 但是,您可以从“p4 info”的输出中获取它们,并且您可以使用-F全局选项来p4以最小的方式隔离任一字段:
Client root: 客户端根:
p4 -Ztag -F %clientRoot% info
Server root: 服务器根:
p4 -Ztag -F %serverRoot% info
See http://www.perforce.com/blog/130826/fun-formatting for more on the -F option. 有关-F选项的更多信息,请参见http://www.perforce.com/blog/130826/fun-formatting 。
You can parse the output of p4 set P4CLIENT
to get the client name, then parse the output of p4 client clientname
to get the root. 您可以解析p4 set P4CLIENT
的输出以获取客户端名称,然后解析p4 client clientname
的输出以获取root。 Ugly, but functional: 丑陋,但功能:
@for /f "tokens=2 delims== " %c in ('p4 set P4CLIENT') do @(for /f "tokens=2" %r in ('p4 client -o %c ^| findstr /c:"Root:" ^| findstr /v #') do echo %r)
If you're using this in a batch file, double each of the percent signs. 如果您在批处理文件中使用它,请将每个百分号加倍。
EDIT - Alternately, and much easier, now that I look at it: 编辑 - 或者,更容易,现在我看一下:
for /f "tokens=3" %r in ('p4 info ^| findstr /c:"Client root:"') do echo %r
Again, double the percents if you're using this in a batch file. 如果您在批处理文件中使用它,则再次加倍百分比。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.