Global options

Global options for Helix Core Server commands can be supplied on the command line before any Helix Core Server command.

Syntax

p4 [-b batchsize -c client -d dir -H host -p port -P pass -v var -u user -x file
     -C charset -Q charset -L language] [-I] [-G] [-Mj] [-s] [-z tag] cmd [args ...]
p4 -V
p4 -h

Syntax conventions

Options

-b batchsize

Specifies a batch size (number of arguments) to use when processing a command from a file with the -x argfile option. By default, the batch size is 128.

-c client

Overrides any P4CLIENT setting with the specified client name.

-d dir

Overrides any PWD setting (current working directory) and replaces it with the specified directory.

-I

Specify that progress indicators, if available, are desired. This option is not compatible with the -s and -G options.

-i Although not global, the -i and -o options work with forms and represent standard in and standard out.

-G

Causes all output (and batch input for form commands with -i) to be formatted as marshaled Python dictionary objects. This is most often used when scripting.

Note

Use the -G option with the -z tag option. Otherwise the marshaled output might be invalid.

See also the Usage notes.

-Mj

Formats output as line-delimited JSON objects, with non-UTF8 characters replaced with U+FFFD

Note

Use the -Mj option with the -z tag option. Otherwise the marshaled output might be invalid.

-H host

Overrides any P4HOST setting and replaces it with the specified hostname.

-o Although not global, the -i and -o options work with forms and represent standard in and standard out.

-p port

Overrides any P4PORT setting with the specified protocol:host:port.

-P pass

Enables a password (or ticket) to be passed on the command line, thus bypassing the password associated with P4PASSWD. If a valid ticket exists, using this option with an invalid pass causes access to be granted by the valid ticket.

-r retries

Specifies the number of times to retry a command (notably, p4 sync) if the network times out.

-s

Prepends a descriptive field (for example, text:, info:, error:, exit:) to each line of output produced by a Helix Core Server command. This is most often used when scripting.

-u user

Overrides any P4USER, USER, or USERNAME setting with the specified user name.

-x argfile

Instructs Helix Core Server to read arguments, one per line, from the specified file.

If argfile is a single hyphen (-), instructs Helix Core Server to read from standard input instead of from a file.

-C charset

Overrides any P4CHARSET setting with the specified character set.

-Q charset

Overrides any P4COMMANDCHARSET setting with the specified character set.

-L language

This feature is reserved for system integrators.

-z tag

Causes output of many reporting commands to be in the same tagged format as that generated by p4 fstat.

Note

Use this option for all marshaled output, such as that of -G and -Mj. Otherwise the marshaled output might be invalid.

See also the Timestamp and Unix epoch time information.

-q

Quiet mode, which suppresses informational messages and reports only warnings or errors.

-v var

Debug level or configurable represented by var, such as:

p4 -v 1 info

or

p4 -v net.autotune=0 info

-V

Displays the version of the p4 application and exits.

-h

Displays basic usage information and exits.

Usage notes

  • Be aware that the global options must be specified on the command line before the Helix Core Server command. Options specified after the Helix Core Server command will not be interpreted as global options, but as options for the command being invoked. It is therefore possible to have the same command line option appearing twice in the same command, being interpreted differently each time.

    For example, the command p4 -c anotherclient edit -c 140 file.c will open file file.c for edit in pending changelist 140 under client workspace anotherclient.

  • The -x option is useful for automating tedious tasks because it processes a sequence of arguments, line by line, from the specified file. For example, suppose you want an easy way to bring many files into the depot. Create one file that lists many files, each on a separate line. Let's use the UNIX cat command to verify we have such a file:

    cat filesToAdd.txt
    partOne.txt
    partTwo.txt
    partThree.txt

    The -x option enables the p4 add command to process each line of the file as if we had issued a series of p4 add commands, each time with a different file argument. In this case,

    p4 -x filesToAdd.txt add

    is the equivalent of:

    p4 add partOne.txt
    
    p4 add partTwo.txt
    p4 add partThree.txt

    Therefore, the result of p4 -x filesToAdd.txt can be:

    //depot/repo/partOne.txt#1 - opened for add
    //depot/repo/partTwo.txt#1 - opened for add
    //depot/repo/partThree.txt#1 - opened for add

    The -x option can be as powerful as whatever generates its input. For example, a UNIX developer who wants to edit any file referring to a file.h file can issue the command:

    grep -l file.h *.c | cut -f1 -d: | p4 -x - edit

    where:

    • the grep command lists occurrences of file.h in the *.c files
    • the -l option tells grep to list each file only once
    • the cut command splits off the filename from grep's output before passing it to the p4 -x - edit command
  • The -s option can be useful in automated scripts.

    For example, a script could be written as part of an in-house build process which executes p4 -s commands, discards any output lines beginning with "info:", and alerts the user if any output lines begin with "error:".

  • Python developers find the -G option useful for scripting. For instance, to get a dictionary of all the fields of a job whose ID is known, use the following:

    job_dict = marshal.load(os.popen('p4 -G job -o ' + job_id, 'rb'))

    In some cases, it might not be obvious which keys are used by the application. If you pipe the output of any p4 -G invocation to the following script, you will see every record printed out in key/value pairs:

    #!/usr/local/bin/python
    
    import marshal, sys
    
    try:
        num=0
        while 1:
            num=num+1
            print '\n' % num
            dict = marshal.load(sys.stdin)
            for key in dict.keys(): print "%s: %s" % (key,dict[key])
    
    except EOFError: pass

    Python developers on Windows should be aware of potential CR/LF translation issues. In the example above, it is necessary to call marshal.load() to read the data in binary ("rb") mode.

    Tip

    For additional examples and guidance about scripting with this option, see the Perforce Knowledge Base article, Using p4 -G.

  • The progress indicator requested when you use the -I option is only available with p4 -I submit and p4 -I sync -q
  • p4 help is simpler than p4 -c workspace help and provides the same output.

Examples

p4 -p new_service:1234 sync

Performs a sync after connecting to new_service and port 1234, regardless of the settings of the P4PORT environment variable.

p4 -c new_client submit -c 100

The first -c is the global option to specify the client workspace name.

The second -c specifies a changelist number.

p4 -s -x filelist.txt edit

If filelist.txt contains a list of files, this command opens each file on the list for editing, and produces output suitable for parsing by scripts.

Any errors as a result of the automated p4 edit commands (for example, a file in filelist.txt not being found) can be detected by examining the command’s output for lines beginning with "error:"