Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perforce : Is there any command to check if client spec exist or not

Actually i need write one batch script, in that first i need to check if the required client spec already exist or not? If exist then i should delete it.

Could you please let us know how can we check in a script, if the required client spec exist or not?

like image 275
user2369546 Avatar asked Oct 28 '13 09:10

user2369546


1 Answers

On Windows command line you can do something like this

set P4CLIENT=client-name
p4 clients -e %P4CLIENT% | findstr %P4CLIENT% >nul

p4 clients -e %P4CLIENT% will output all clients matching %P4CLIENT%. findstr will search the output of p4 clients for the client name and print it. The redirection to to nul will supress this output, but findstr will additionally set the %errorlevel% variable.

Some examples:

p4 clients -e existing-client | findstr existing-client >nul
echo %errorlevel%

Will return 0.

p4 clients -e does-not-exists | findstr does-not-exists >nul
echo %errorlevel%

Will return 1.

If you want to execute something, if a given client space does not exists, you can run this command:

p4 clients -e does-not-exists | findstr does-not-exists >nul || create-client.bat

If you want to execute something, if a given client space does exists, you can run this command:

p4 clients -e does-not-exists | findstr does-not-exists >nul && do-something.bat

Thanks to Adam from the perforce online chat support!

like image 176
pdx9k9e9 Avatar answered Sep 23 '22 11:09

pdx9k9e9