{"id":4572,"date":"2018-01-09T06:17:30","date_gmt":"2018-01-09T06:17:30","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=4572"},"modified":"2025-02-01T22:39:32","modified_gmt":"2025-02-01T22:39:32","slug":"perforce-command-line-global-options","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/perforce-command-line-global-options\/","title":{"rendered":"Perforce Command Line Global Options"},"content":{"rendered":"<p>&lt;!&#8211; .style1 { font-size: 24px; font-weight: bold; } &#8211;&gt;<\/p>\n<p><strong>Perforce Command Line Global Options<\/strong><\/p>\n<p><a name=\"1040703\"><\/a>Global options for Perforce commands; these options can be supplied on the command\u00a0line before any Perforce command.<\/p>\n<div><strong><a name=\"1045522\"><\/a>Syntax<\/strong><\/div>\n<div><a name=\"1045523\"><\/a>p4 [-cclient -ddir -Hhost -pport -Ppass -uuser -xfile -Ccharset -Qcharset -Llanguage] [-G] [-s] [-z tag] cmd [args &#8230;]<br \/>\np4 -V<br \/>\np4 -h<\/div>\n<p>&nbsp;<\/p>\n<div><a name=\"1045577\"><\/a><strong>Options<\/strong><\/div>\n<table border=\"0\" cellspacing=\"0\">\n<caption>\u00a0<\/caption>\n<tbody>\n<tr>\n<td>\n<div><a name=\"1045526\"><\/a>-c\u00a0client<\/div>\n<\/td>\n<td>\n<div><a name=\"1045530\"><\/a>Overrides any\u00a0<a href=\"http:\/\/www.perforce.com\/perforce\/doc.current\/manuals\/cmdref\/env.P4CLIENT.html#1040647\" target=\"_blank\" rel=\"noopener\">P4CLIENT<\/a>\u00a0setting with the specified client name.<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<div><a name=\"1045532\"><\/a>-d\u00a0dir<\/div>\n<\/td>\n<td>\n<div><a name=\"1045535\"><\/a>Overrides any\u00a0<a href=\"http:\/\/www.perforce.com\/perforce\/doc.current\/manuals\/cmdref\/env.PWD.html#1040647\" target=\"_blank\" rel=\"noopener\">PWD<\/a>\u00a0setting (i.e. current working directory) and replaces it with the specified directory.<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<div><a name=\"1045537\"><\/a>-G<\/div>\n<\/td>\n<td>\n<div><a name=\"1045540\"><\/a>Causes all output (and batch input for form commands with\u00a0-i) to be formatted as marshalled Python dictionary objects. This is most often used when scripting.<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<div><a name=\"1045542\"><\/a>-H\u00a0host<\/div>\n<\/td>\n<td>\n<div><a name=\"1045545\"><\/a>Overrides any\u00a0<a href=\"http:\/\/www.perforce.com\/perforce\/doc.current\/manuals\/cmdref\/env.P4HOST.html#1040647\" target=\"_blank\" rel=\"noopener\">P4HOST<\/a>\u00a0setting and replaces it with the specified hostname.<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<div><a name=\"1045547\"><\/a>-p\u00a0port<\/div>\n<\/td>\n<td>\n<div><a name=\"1045550\"><\/a>Overrides any\u00a0<a href=\"http:\/\/www.perforce.com\/perforce\/doc.current\/manuals\/cmdref\/env.P4PORT.html#1040647\" target=\"_blank\" rel=\"noopener\">P4PORT<\/a>\u00a0setting with the specified port number.<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<div><a name=\"1045552\"><\/a>-P\u00a0pass<\/div>\n<\/td>\n<td>\n<div><a name=\"1045555\"><\/a>Overrides any\u00a0<a href=\"http:\/\/www.perforce.com\/perforce\/doc.current\/manuals\/cmdref\/env.P4PASSWD.html#1040647\" target=\"_blank\" rel=\"noopener\">P4PASSWD<\/a>\u00a0setting with the specified password.<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<div><a name=\"1045584\"><\/a>-s<\/div>\n<\/td>\n<td>\n<div><a name=\"1045587\"><\/a>Prepends a descriptive field (for example,\u00a0text:, info:, error:, exit:) to each line of output produced by a Perforce command. This is most often used when scripting.<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<div><a name=\"1045557\"><\/a>-u\u00a0user<\/div>\n<\/td>\n<td>\n<div><a name=\"1045560\"><\/a>Overrides any\u00a0<a href=\"http:\/\/www.perforce.com\/perforce\/doc.current\/manuals\/cmdref\/env.P4USER.html#1040647\" target=\"_blank\" rel=\"noopener\">P4USER<\/a>, USER, or USERNAME setting with the specified user name.<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<div><a name=\"1045567\"><\/a>-x\u00a0file<\/div>\n<\/td>\n<td>\n<div><a name=\"1045569\"><\/a>Instructs Perforce to read arguments, one per line, from the\u00a0specified file. If file is a single hyphen (-), then standard input is read.<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<div><a name=\"1048258\"><\/a>-C\u00a0charset<\/div>\n<\/td>\n<td>\n<div><a name=\"1048260\"><\/a>Overrides any\u00a0<a href=\"http:\/\/www.perforce.com\/perforce\/doc.current\/manuals\/cmdref\/env.P4CHARSET.html#1040647\" target=\"_blank\" rel=\"noopener\">P4CHARSET<\/a>\u00a0setting with the specified character set.<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<div><a name=\"1048527\"><\/a>-Q\u00a0charset<\/div>\n<\/td>\n<td>\n<div><a name=\"1048530\"><\/a>Overrides any\u00a0<a href=\"http:\/\/www.perforce.com\/perforce\/doc.current\/manuals\/cmdref\/env.P4COMMANDCHARSET.html#1040647\" target=\"_blank\" rel=\"noopener\">P4COMMANDCHARSET<\/a>\u00a0setting with the specified character set.<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<div><a name=\"1048273\"><\/a>-L\u00a0language<\/div>\n<\/td>\n<td>\n<div><a name=\"1048275\"><\/a>This feature is reserved for system integrators.<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<div><a name=\"1048678\"><\/a>-z tag<\/div>\n<\/td>\n<td>\n<div><a name=\"1048680\"><\/a>Causes output of many reporting commands to be in the same\u00a0tagged format as that generated by\u00a0<a href=\"http:\/\/www.perforce.com\/perforce\/doc.current\/manuals\/cmdref\/fstat.html#1040665\" target=\"_blank\" rel=\"noopener\">p4 fstat<\/a>.<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<div><a name=\"1045590\"><\/a>-V<\/div>\n<\/td>\n<td>\n<div><a name=\"1045592\"><\/a>Displays the version of the\u00a0p4 client program and exits.<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<div><a name=\"1048266\"><\/a>-h<\/div>\n<\/td>\n<td>\n<div><a name=\"1048268\"><\/a>Displays basic usage information and exits.<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<div><a name=\"1040576\"><\/a><strong>Usage Notes<\/strong><\/div>\n<div>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>\u2022<\/div>\n<\/td>\n<td>\n<div><a name=\"1040577\"><\/a>Be aware that the global options must be specified on the command line before the\u00a0Perforce command. Options specified after the Perforce 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.<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div><a name=\"1040777\"><\/a>For example, the command\u00a0p4 -c anotherclient edit -c 140 file.c will open file file.c for edit in pending changelist 140 under client workspace anotherclient.<\/div>\n<div>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>\u2022<\/div>\n<\/td>\n<td>\n<div><a name=\"1040722\"><\/a>The\u00a0-x option is useful for automating tedious tasks; a user adding several files at once could create a text file with the names of these files and invoke p4 -x textfile add to add them all at once.<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div><a name=\"1040723\"><\/a>The\u00a0-x option can be extremely powerful &#8211; as powerful as whatever generates its input. For example, a UNIX developer wishing to edit any file referring to an included file.h file, for instance, could grep -l file.h *.c | cut -f1 -d: | p4 -x &#8211; edit.<\/div>\n<div><a name=\"1040778\"><\/a>In this example, the\u00a0grep command lists occurrences of file.h in the *.c files, the -l option tells grep to list each file only once, and the cut command splits off the filename from grep&#8217;s output before passing it to the p4 -x command.<\/div>\n<div>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>\u2022<\/div>\n<\/td>\n<td>\n<div><a name=\"1040724\"><\/a>The\u00a0-s option can be useful in automated scripts.<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div><a name=\"1040776\"><\/a>For example, a script could be written as part of an in-house build process which\u00a0executes p4 -s commands, discards any output lines beginning with &#8220;info:&#8221;, and alerts the user if any output lines begin with &#8220;error:&#8221;.<\/div>\n<div>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>\u2022<\/div>\n<\/td>\n<td>\n<div><a name=\"1045402\"><\/a>Python developers will find the\u00a0-G option extremely useful for scripting. For instance, to get a dictionary of all fields of a job whose ID is known, use the following:<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div><a name=\"1045409\"><\/a>job_dict = marshal.load(os.popen(&#8216;p4 -G job -o &#8216; + job_id, &#8216;rb&#8217;))<\/div>\n<div><a name=\"1048244\"><\/a>In some cases, it may not be intuitively obvious what keys are used by the client\u00a0program. 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:<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&lt;!&#8211; .style1 { font-size: 24px; font-weight: bold; } &#8211;&gt; Perforce Command Line Global Options Global options for Perforce commands; these options can be supplied on the command\u00a0line before any Perforce command. Syntax p4 [-cclient -ddir -Hhost -pport -Ppass -uuser -xfile -Ccharset -Qcharset -Llanguage] [-G] [-s] [-z tag] cmd [args &#8230;] p4 -V p4 -h &nbsp;&#8230;<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[370],"tags":[824,1961,373,4491,3204,3214],"class_list":["post-4572","post","type-post","status-publish","format-standard","hentry","category-perforce","tag-command-line","tag-p4-command-line","tag-perforce","tag-perforce-command-line-cheatsheet","tag-perforce-command-line","tag-perforce-command-line-reference"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/4572","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=4572"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/4572\/revisions"}],"predecessor-version":[{"id":4573,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/4572\/revisions\/4573"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=4572"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=4572"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=4572"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}