How do I get the perforce root directory from command line?
Solution 1
If you want your client root in one command run:
p4 -F %clientRoot% -ztag info
You will need the 2014.1 later version of p4 to use this flag.
Solution 2
For older versions before 2014.1 use the command
p4 info | grep 'Client root:' | cut -d ' ' -f 3-
Solution 3
From OP’s description, they probably want p4 where
. For example, if the client root is /perforce/projects
, then
p4 where //depot/project-1/module-2
will give /perforce/projects/project-1/module-2
. Credit from Bryan’s comment.
Related videos on Youtube
thisisdog
Updated on September 16, 2022Comments
-
thisisdog over 1 year
How do I get the perforce root directory from the command line? I've tried
p4 info
but I'd rather not have to filter this to get at the root. I'm sure there's a way, but I couldn't find it.Is there a way to get the root in a context sensitive way? For example if I have two workspaces with a hierarchy like A/.../script vs B/.../script I'd expect that the script would return either A or B depending on where it was run from.
-
Christopher Creutzig about 10 yearsI'm not sure what the problem with
p4 info | grep 'Client root:' | cut -d ' ' -f 3-
is that you're trying to avoid. But I never checked if, e.g.,p4 info
is localized – and if not, that might change in the future. -
Bryan Pendleton about 10 yearsThen it sounds like you want 'p4 where //depot/A/B/C'.
-
Franklin Yu over 4 years@BryanPendleton Please promote your comment into an answer. I think a significant portion of readers of this question actually want this. Also link to manual for
p4 where
would be helpful.
-
-
Tor Klingberg over 9 yearsIt works for me. You may have older version of the P4 client some1.
-
Matt over 9 yearsYou're correct Tor. I've updated the answer to clarify.
-
gws about 6 yearsThis breaks if 'clientRoot' is already set in the environment. Escape the second percent sign:
%clientRoot^%
. But because CMD is special that only works if you type it yourself at a prompt. To do it in a batch file you have to say%%clientRoot^^^%%
, which is pretty hideous. -
Andreas about 4 yearsThis works pretty fine but out of curiosity, do you know how the %clientRoot% variable is set? I tested this with 2 different roots that both have P4CLIENT set in a P4CONFIG.txt file so probably clientRoot is set through P4CLIENT?
-
Andreas about 4 years@Matt ...also, what's that -ztag parameter for?
-
Matt over 3 yearsThe -ztag tells p4 to dump out the dictionary of values sent back from the server. For a lot of commands the server sends back more info than the client uses when formatting the message