Using Perforce Counters to control syncing
Perforce has a handy system of built in variables you can use which are visible to all users for a particular server, these variables are called Counters. Counters are very handy way to distribute Perforce specific information e.g. the last change list that successfully passed automated testing.
Its relatively easy to write a batch file to sync to the change list specified in a counter. Although it isn’t pretty due to the limitations of batch scripting: first pipe the output from the p4 counter command into a temporary file, use the contents of the file to set a batch variable, then delete the temporary file (to keep things tidy) and finally call P4 sync with your Perforce path and the new batch variable.
echo off REM Get change list specified in counter. p4 counter <COUNTERNAME> > CL.txt set /p CL= < CL.txt del CL.txt REM Sync Perforce to change list specified in counter. p4 sync <P4PATH>@%CL%
I usually specify the port, user and client when I am using Perforce from a script to make sure the correct server/user/client is used as I login to many different Perforce servers so its not guaranteed that the correct server is setup in the command line environment. To specify the port, username and client spec to use insert the following after ‘p4′ and before the sync/counter command.
P4 -p <PORT> -u <USERNAME> -c <CLIENT> <CMD> <CMD ARGS>
I use a script like this to avoid syncing to known broken change lists, which is a big time saver









