Luc Shelton

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

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

Created 2 years ago
2 Minute(s) to read
Posted 2 years ago Created 2 years ago 2 Minute(s) to read 0 comments

Overview

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
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
p4 -e info

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.



Comments

Comments