Looking to get P4PORT from p4api.net

178 Views Asked by At

It seems the call is Connection.GetP4EnvironmentVar( "P4PORT" ), but to be able to interrogate a connection I need to connect to a server and hence need a P4PORT in advance, and so have a chicken and egg situation. What is the best practice in this situation? Look in "HKCU\SOFTWARE\perforce\environment" ?

The goal is to run a C# app that can read the P4 env variables to grab P4PORT.

Cheers John

1

There are 1 best solutions below

1
On

Per the spec fetcher example in the doc, you can create a ServerAddress with an empty URI -- this isn't explicitly explained in the doc, but that must be how to have your app get P4PORT from the environment. Assuming that the logic to pull P4PORT from the environment lives in ServerAddress, you might be able to do something like:

string p4Port = ServerAddress("").Uri;

If not, then it might need to be a more convoluted incantation along the lines of:

Server server = new Server(new ServerAddress(""));
string p4Port = server.Address.Uri;

or even:

Repository rep = new Repository(new Server(new ServerAddress("")));
string p4Port = rep.Connection.GetP4EnvironmentVar("P4PORT");