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.
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
-F command-line parameters.
Using -ztag parameter
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.
p4 -ztag info
Which produces an an output similar to the screenshot below.
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.
p4 -e info
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.