Submitting Files Non-interactively

How do you submit files from a program or batch script?

Info & Tags

Article #:
6
Created:
02/23/07
Modified:
01/09/08

PROBLEM

How do you submit files from a program or batch script?
How do you prevent "submit" from starting up an editor?

SOLUTION

Release 2006.2 (or later)

You can use the -d option on the submit command to pass in the changelist description:
p4 submit -d description

This will immediately submit the default changelist with the description supplied (after the "-d" flag) on the command line, and bypass the interactive form. Multiple words with spaces should be enclosed in qotes:

p4 submit -d "This is a description"
Note: This option is useful when scripting but does not allow for jobs to be added or the default changelist to be modified.


All Releases

You can use
p4 submit -i 

to prevent an editor from being started interactively. The -i flag causes submit to read data from standard input. For example:

p4 submit -i < inputfile

In order for this submit to succeed, inputfile must be a valid, completed submit form. Here's an example of what that file might look like:

Change:	new
Description:
Modify web pages.
Files:
//depot/www/index.html
//depot/www/products.html

Note that lines which do not introduce fields must start with a space or tab (in the above example, lines that introduce fields are "Change:", "Description:", and "Files:").

An easy way to create a valid input template for p4 submit is:

p4 change -o

You can then use your script to modify this output with data you provide. The p4 change output lists opened files in the current workspace, so typically the only information you have to provide is a change description. For example, an sh script (Unix/Linux) could do something like this:

p4 change -o | 
sed "s/<enter description here>/Nightly build results/" |
p4 submit -i

Note: for Windows/DOS, there are different Unix-like utilities available (both open source and commercially) that would allow you to do this as well.

An alternative is to have your script create a numbered change, capture the changelist number, and submit that numbered change. These are the commands your script will need to issue:

p4 change -i < inputfile
p4 submit -c changenum
where changenum is the changelist number generated by the previous "p4 change" command. This of course assumes inputfile contains a valid submit form, and that your script captured the new changelist number and stored it in changenum