Login to Perforce from Commandline
Before connecting to the server, set P4PORT (to tell the client where the server is) and P4USER (to tell the server who you are). P4PORT is specified as hostname:port, with the port usually (but not always) being 1666. If you're not sure what your Perforce server address and user name are, check with your sys admin.
p4 set P4PORT=your.server.hostname:1666
p4 set P4USER=your.username
You can also use "set" or "setenv" or "export" as appropriate to your shell, but with a 2014.2 or newer Perforce client (use "p4 -V" to check your version information) you can use "p4 set" as a persistent cross-platform alternative. Another option is to use the "-u" and "-p" flags on every command you run (e.g. "p4 -p your.server.hostname:1666 -u your.username sync ..."), but this gets tiresome quickly.
To verify that your connection is correct, run:
p4 info
If this gives you an error message, or says that your user is unknown, check with your Perforce administrator to make sure you have the correct P4PORT and P4USER values.
To login, run:
p4 login
If the client is able to connect to the server and your user name is correct, you will be prompted for the password. Enter it and you will be logged in.
If you are scripting Perforce commands that require login credentials, and you don't want your script to stop in the middle to prompt for a password, my recommendation would be to run "p4 login" as above at some point prior to running the script. The login ticket will persist on your machine and the script will pick it up (provided that it's connecting with the same P4PORT and P4USER that you used to generate the ticket). This is the most secure method because your cleartext password is not stored anywhere on your machine, and the login ticket is not usable from other machines by default (it is also probably time-limited, depending on how your admin has configured things).
The insecure method is to put the plaintext password into your script:
echo my.formerly.secure.password|p4 login
Piping the cleartext of the password into the "p4 login" command will cause it to behave as if you'd entered it at the prompt, and continue executing rather than waiting for additional input.
Setup Perforce login details in Windows cmd
After installing perforce and setup your workspace through p4v, you could set up your workspace in Windows cmd.
The command you need is:
p4 set
Set your server
p4 set P4PORT= xx.xxx.xx.xxx:xxxxx
Set your user name
p4 set P4USER=username
Set your password
If you want to secure your password, you could download the MD5 encryptor to encrypt your password.
p4 set P4PASSWD=hashedpasswd
Set you client (workspace)
In order to select your workspace, you could use the following command:
p4 set P4CLIENT=nameofworkspace
The name of your workspace could look like: username_hostmachinename_numbers.
Set your ignore file
You can set up your ignore file so that when adding your project to perforce, some files (building results) could be automatically ignored.
p4 set P4IGNORE= filepath