Jump to content

Need p4 command to list all clients on a host


  • Please log in to reply
4 replies to this topic

#1 BillF



  • Members
  • Pip
  • 2 posts

Posted 07 February 2017 - 04:51 PM

I am looking for either a single p4 command or the best sequence of Windows batch file commands, that will find all the p4 clients that currently exist for a given host.

I am aware of the suggested method that a web search mentions, using 'p4 clients' to find all clients on the p4 server, and then iterate the list, executing the command 'p4 client -o %ClientNameToCheck%, and then parsing the output to find the 'Host:%HOSTNAME%" line.

However this approach takes several minutes to complete, since these are 2551 clients on the server to check.

There must be a better command to achieve this need.   Even P4V can quickly find all clients for a given host, by checking the "Show only workspaces available for use on this computer" checkbox on the "Workspaces" filter.  P4V finds all clients in 1 or 2 secs.

Any suggestions?  Thanks.

#2 P4Reg


    Advanced Member

  • Staff Moderators
  • 105 posts

Posted 07 February 2017 - 05:53 PM

You could try the formatted output option to p4 (see https://www.perforce.../fun-formatting)

p4 -ztag -F "%client%,%Host%" clients

You can then filter on host

#3 BillF



  • Members
  • Pip
  • 2 posts

Posted 07 February 2017 - 08:28 PM

Thanks Newbie.  Your reply was what I was looking for.  I am now using the following command to find clients on a given HOST:

p4 -ztag -F %%client%%,%%Host%% clients | findstr /R /I /C:"^.*,%HOST%$"

This command completes in less than 1 sec.  Better than calling "p4 client -o" 2,551 times.

I am now challenged to get the names of all host clients into a single cmd script variable.  Any suggestions would be welcomed.

#4 Sambwise


    Advanced Member

  • Members
  • PipPipPip
  • 1191 posts

Posted 07 February 2017 - 10:49 PM

View PostBillF, on 07 February 2017 - 08:28 PM, said:

Any suggestions would be welcomed.

Use an easier scripting language?

(You did say any suggestions...)

#5 myocom



  • Members
  • PipPip
  • 24 posts

Posted 07 February 2017 - 10:56 PM

@Sam - Bah, where's your sense of adventure?! :)

@Bill, if you just want the client names (seems likely, since you're already feeding the script your hostname of interest) you could do this, which will put those client names, semicolon-delimited, in %LIST%:

@echo off
set LIST=

for /f "tokens=1" %%x in ('p4 -ztag -F "%%client%%,%%Host%%" clients ^| findstr /R /I /C:"^.*,%SEARCHHOST%$"') do call :AddClient %%x

REM Strip off the final ;
set LIST=%LIST:~0,-1%

echo Clients bound to host '%SEARCHHOST%':
echo %LIST%
exit /b

set LIST=%1;%LIST%

Also tagged with one or more of these keywords: p4

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users