Submitting Files Non-interactively
Submit files from a program or batch script
PROBLEM
How do I submit files from a program or batch script?
How do I prevent submit from starting up an editor?
SOLUTION
Release 2006.2 (or later)
You can use the -d option on the p4 submit command to pass in the changelist description:
p4 submit -d description
This command immediately submits the default changelist with the description supplied (after the -d flag) on the command line, and bypasses the interactive form. Enclose multiple words with spaces in quotes:
p4 submit -d "This is a description"
Note: the -d option is useful when scripting but does not allow for jobs to be added or the default changelist to be modified.
All Releases
To prevent an editor from being started interactively, you can use
p4 submit -i
The -i flag causes p4 submit to read data from standard input. For example:
p4 submit -i < inputfile
For this p4 submit to succeed, inputfile must be a valid, completed submit form. Here is 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 can allow you to do this.
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 needs 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
