Perforce Public Knowledge Base - Invoking P4V from the command line
Reset Search



Invoking P4V from the command line

« Go Back



P4V has supported external invocation to access the Timelapse View and Revision Graph since 2004.2. This has, for example, allowed P4Win to use these features. It also provides some limited capabilities for external scripts to invoke P4V from the command line.

Warning: These P4V command line options are unsupported and subject to change without notice.


P4V command syntax is:

p4v {options} {-cmd "command {file path}"}

Note: Under Mac OS X you will need to specify the full path to a specific resource inside For example, if P4V is located in the Applications directory, this command will display the version information:

/Applications/ -V

The available options to invoke P4V (version 2004.2 and later) are:

-pPerforce server host:port (P4PORT)
-PPerforce password (P4PASSWD)
-uPerforce user (P4USER)
-cWorkspace client (P4CLIENT)
-CProperties of the specified file  (P4CHARSET)
-logLog P4 user commands to STDOUT
-logallLog all P4 commands to STDOUT
-VPrint P4V version information to STDOUT
-hShow available commands and flags

Note: The user (-u) and port (-p) flags are mandatory, even if those values are set as registry values. The charset (-C), password (-P), and client (-c)( flags are optional, and are likewise the only way to specify these values to P4V. To work around this limitation in your script you will need to extract the current values using the "p4 set" command and pass them with the appropriate flags to P4V. See the knowledge base article on Accessing Perforce Environment Variables From a Windows Batch File for further instructions.

Note: If the specified port and user have not already established a valid ticket, and the password is not provided, the user will be prompted to enter a password. If a valid password is provided, P4V opens and completes any additional commands.

No password is required for the -V nor -h flags.

Logging Output

Both the -log and -logall options require that the output be re-directed to a file.


./p4v.real {-log or -logall} {other options} > log_file.txt

The main difference between -log and -logall is that -logall will include the P4 commands issued by P4V. For example, output that appears in the logfile for -logall output:

2:23:36 AM: p4 add -d -f -c default c:\p4ws\depot\foo.txt
2:23:36 AM: 1 file opened for add
2:23:53 AM: p4 edit -c default c:\p4ws\depot\bar.txt
2:23:53 AM: 1 file opened for edit

Would appear as this when using the -log flag for the same commands:

2:23:36 AM: 1 file opened for add
2:23:53 AM: 1 file opened for edit

Help and Version Output

The help output from the -h flag and the version information from the -V flag is displayed in a dialog in P4V itself.

Starting with version 2010.2 P4V now has the following new options available:

-sSelects a file in the depot tree when opening P4V
-tOpen P4V with the tab specified shown and selected


This command line entry launches P4V, connects to a server, and selects the file //depot/foo.txt in the depot tree. The History tab is selected showing the selected file history:

p4v -p myserver:1666 -C utf8 -u bruno -t history -s //depot/foo.txt 

You can specify the workspace file tree instead by specifying a local path to the file. This requires that you also specify a client workspace:

p4v -p myserver:1666 -C utf8 -c a_client -u bruno -t history -s c:\p4_ws\depot\foo.txt 

Failing to specify a workspace will generate an error similar to:

c:\p4_ws\depot\foo.txt - must create client '_____CLIENT_UNSET_____' to access local files.

Note: This error will be displayed in a P4V error dialog, not the command line.


Options for the -cmd Flag

historyFile history of the specified file
open Open P4V with the specified file selected
submitSubmit the specified file (if open on specified client)
propertiesProperties of the specified file
diffdialogOpen a dialog to specify two file revisions to compare
prevdiffCompare the local file against the have revision
annotateTimelapse View of the specified file
treeRevision graph of the specified file

The syntax to call P4V from the command line with the above commands is:

p4v {options} -cmd "cmd path-to-file"
Note: The quotes around the command and the path are required. Unless otherwise specified, the P4V main window is not displayed as a result of those commands, only the specified window.


This -cmd option is similar to:
p4v {options} -t history -s c:\p4_ws\depot\foo.txt
The main difference is that only the History window is displayed, instead of the P4V tab:
p4v {options} -cmd "history c:\p4_ws\depot\foo.txt"
Note: The file path must be local.


This command is identical to using the -s flag to specify a selected file if no tab is specified using the -t flag.  Therefore, those two commands produce the same result (the P4V main window is displayed with the selected file):
p4v {options} -s //depot/bar.c
p4v {options} -cmd "open //depot/bar.c"
Either local or depot path syntax is valid.


This command will submit the specified file:
p4v {options} -cmd "submit //depot/bar.c"
Note: If the file is not currently open for add, edit or delete the command will fail silently. It will also fail if you attempt to specify the "..." wild card. For example, this command will fail:
p4v {options} -cmd "submit //depot/..."


This displays a window showing the file properties, similar to the Files tab in the P4V main window. The chief difference is no preview tab is included.


Displays the P4V diff dialog with the specified file:
p4v {options} -cmd "diffdialog //depot/test.h"
The default is to compare the latest (head) revision with the file synced to the workspace. To specify another revision you can add a revision specifier. For example, this command compares the workspace revision with revision 12 of the specified file:
p4v {options} -cmd "diffdialog //depot/test.h#12"
Note: This will not work with a changelist number nor with a specifier like "have" nor "head". The path can be in depot or local syntax. Only the diff dialog is displayed -- the diff is not performed until the user clicks the "Diff" button.
Automatically compares the specified workspace file against the "have" revision. File path can be in local or depot syntax.


Displays the specified file in Timelapse view. File path can be in local or depot syntax.


Displays the specified file as a Revision Graph. File path can be in local or depot syntax.
Related Links



Was this article helpful?



Please tell us how we can make this article more useful.

Characters Remaining: 255