Luc Shelton

Perforce: Formatting, Scripting, and the Command-line Interface

Perforce: Formatting, Scripting, and the Command-line Interface

Perforce: Formatting, Scripting, and the Command-line Interface

Perforce: Formatting, Scripting, and the Command-line Interface

Updated 2 years ago
3 Minute(s) to read
Posted 5 years ago Updated 2 years ago 3 Minute(s) to read 0 comments

In this blog post I will discuss some of the convenient tricks that you can leverage when navigating Perforce and its command-line interface. A lot of these are well documented in a post that's available on Perforce's website, but this blog post will look at a few of those features with more detail.


Formatting Output

The Perforce command-line interface features support for a variety of useful global command-line arguments that can be used for altering the output and and operation of the command-line tool.

The output from the Perforce command-line interface can be formatted using a combination of the -ztag, -e, and -F command-line parameters.

Using -ztag parameter

The -ztag global command-line parameter displays the standard output from the Perforce command-line interface in a format that conforms to a specification.

The specification is denoted in that each "key" or "attribute" of an object, is prefixed with "... " and then proceeded by the name of the key. The data for that particular attribute or property is then displayed afterwards using a white-space character as the delimiter. Find below an example.

Usage
#!/bin/bash
p4 -ztag info

Which produces an an output similar to  the screenshot below.

Command Prompt Example

The resulting output from executing "p4 -ztag info"

More information on the p4 info command can be found here.

Using -e and -F parameters

These global command-line arguments are particularly useful for filtering and identifying "keys", "properties", or "attributes" from command outputs. It's possible to see which "keys" are available to filter or "format" our output with by using the -e parameter. The resulting output should look something like this.

Usage
#!/bin/bash
p4 -e info

The -e in this command will now reveal all "formattable" data that is produced by the command info. The parameter "info" can be replaced with another command including "clients", which can display all clients that are owned by the currently logged in user.

#!/bin/bash
p4 -e clients

The above command will display available parameters for each entry that is displayed the "clients" command. Look below at an example of a resulting entry.

info: **REDACTED**
code0 352327909 (sub 229 sys 6 gen 0 args 5 sev 1 uniq 6373)
... code0 352327909
... fmt0 %domainType% %domainName% %updateDate% %'root'% %domainMount% '%description%'
... domainType Client
... domainName **REDACTED**
... updateDate 2021/03/18
... domainMount **REDACTED**
... description Created by **REDACTED**

Under the entry fmt0, we can see that there is a space delimited list of available formatting parameters that we can use. Let's try using the clients command again using one of these parameters.

#!/bin/bash
p4 -F %domainName% clients

The above command should now output each entry that is emitted by the clients command, but only the name. This is because we have selectively chosen which entry to output using %domainName% as the selector.

The same command can be changed to another available formatting parameter such as %updateDate%, which should display the last time the respective client has been updated.

#!/bin/bash
p4 -F %updateDate% clients

Scripting

Understanding how these global command-line parameters can be used is incredibly powerful. With this, we can now write applications that are capable of executing these commands and parsing the stdout stream from the commands we execute with minimal time spent on parsing.


Programming Languages:

Shell Script Bash PowerShell

Technologies:

Helix Core Perforce


Comments

Comments