views:

2166

answers:

4

What is the command-line equivalent of "Switch Port Client User" as found in the p4win gui client?

I am already logged under one port but now I am attempting to connect to a different port on the same server in order to access a separate source control file depot. I assume it would involve using:

p4 login

However, reading the 'help' for 'login' does not show an option to specify the port #. Both user name and client name would remain the same but just need to change the port #.

+5  A: 

The P4PORT configuration variable stores the Perforce server name and port number to connect to. You can set this value as an environment variable or, if you're using Windows, in the registry using 'p4 set':

p4 set P4PORT=perforce:1669

To see what the current value of P4PORT is:

> p4 set P4PORT
P4PORT=perforce:1669
Commodore Jaeger
+1  A: 

E.g:

p4 set P4PORT=1666

From the help:

C:\> p4 help environment

Environment variables used by Perforce:

    Variable    Defines                          For more information see
    --------    -------                          ------------------------
    P4AUDIT     name of server audit file        p4d -h
    P4CHARSET   client's local character set     p4 help charset
    P4COMMANDCHARSET client's local character set for
                command line operations          p4 help charset
    P4CLIENT    name of client workspace         p4 help client
                                                 p4 help usage
    P4CONFIG    name of configuration file       Command Reference Manual
    P4DIFF      diff program to use on client    p4 help diff
    P4DIFFUNICODE diff program to use on client  p4 help diff
    P4EDITOR    editor invoked by p4 commands    p4 help change, etc
    P4HOST      name of host computer            p4 help client
                                                 p4 help usage
    P4JOURNAL   name of server journal file      p4d -h
    P4LANGUAGE  language for text messages       p4 help usage
    P4LOG       name of server log file          p4d -h
    P4MERGE     merge program to use on client   p4 help resolve
    P4MERGEUNICODE merge program to use on client p4 help resolve
    P4PAGER     pager for 'p4 resolve' output    p4 help resolve
    P4PASSWD    user password passed to server   p4 help passwd
    P4PORT      port client connects to          p4 help info
                or server listens on             p4d -h
    P4ROOT      server root directory            p4d -h
    P4TARGET    target server for proxy          Command Reference Manual
    P4TICKETS   location of tickets file         Command Reference Manual
    P4USER      user name                        p4 help usage
    PWD         current working directory        p4 help usage
    TMP, TEMP   directory for temporary files    Command Reference Manual

See 'p4 help set' for details specific to Windows.  The syntax for
setting an environment variable depends on the OS/shell.  Note that many
shells allow the setting of shell variables separate from environment
variables - Perforce cannot see the shell variable, only the environment
variable.

If you are a typical user then the only variables of interest are
$P4CLIENT, $P4PORT and $P4PASSWD.


C:\> p4 help set

set -- Set variables in the registry (Windows only)

p4 set [ -s -S service ] [ var=[value] ]

    'p4 set' sets the registry variables used by Perforce on Windows
    platforms.  Normally, the variable 'var' is set to 'value'.
    If 'value' is missing, the variable 'var' is unset.  Without
    any arguments at all, 'p4 set' list variable settings.

    The -s flag causes 'p4 set' to set variables for the whole system
    rather than for the user.  You must have NT administrator powers
    to use this.

    The -S service flag causes 'p4 set' to set variables for the named
    service.  You must have NT administrator powers to use this.

    Currently, registry variable entries may be overridden by environment
    variables and (in some cases) flags on the command line.
    See 'p4 help environment' for a list of environment/registry variables.
clayless
+2  A: 

You can use a configuration file to set the port that Perforce connects to for each project.

First, create a text file that contains the Perforce configuration variables you want to set for the project. For example, to set the value of P4PORT, the contents of the file would look like this:

P4PORT=hostname:1234

Name the file something descriptive like .p4config and place it in the root of the project folder. Do this for each one of your projects, changing the variables as necessary. Use the same filename.

Then, set the value of P4CONFIG to the name of your configuration files, e.g.

p4 set P4CONFIG=.p4config

This will make Perforce look for configuration values in a file of that name in the current directory or any parent directory, so you don't have to change your configuration variables manually every time you switch projects.

pd
+1  A: 

If you want to do it generically for any P4 command then the general form can be found via "p4 help usage".

In a nutshell,

p4 -p <your port> login

will do what you asked for. Note from the usage help that you can specify most things from the command line such as client spec, username, password, etc.

Greg Whitfield