简体   繁体   English

如何在Windows批处理文件中检索P4 ROOT变量值?

[英]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.

相关问题 如何检测 p4 同步导致冲突? - How can I detect that a p4 sync leads to a conflict? Windows批处理文件-无法设置变量值 - Windows batch File - Can't set variable value 如何检查一个变量是否包含 windows 批处理文件中的另一个变量? - How can I check if a variable contains another variable within a windows batch file? 在批处理文件中,如何获取名称为另一个环境变量的值的环境变量的值? - In a batch file, how can I get the value of an environment variable whose name is the value of another environment variable? 如何将变量添加到批处理文件? - How can I add a variable to a batch file? 如何在Windows批处理文件中将PATH设置为带空格的另一个变量值 - How to set PATH to another variable value with spaces in Windows batch file 如何从Windows批处理文件中的动态变量获取值 - How to get the value from a dynamic variable in windows batch file 如何制作Windows批处理文件来更改环境变量? - How can I make a Windows batch-file which changes an environment variable? 如何在Windows批处理中将环境变量的内容添加到文件中? - How do I add the content of an environment variable to a file in windows batch? 如何将文本文件的内容加载到批处理文件变量中? - How can I load the contents of a text file into a batch file variable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM