[p4] Invoking Perforce from Python

Albrecht, Matt matt.albrecht at zilliant.com
Wed May 9 08:34:00 PDT 2007


You can use the "-d" option to specify what Perforce should consider the
current working directory.  That is:

> p4 -d "/home/myself/workspace/project" files ...

would make the Perforce client use "/home/myself/workspace/project" as
the current working directory.  This eliminates the need for a
"os.chdir" call or "os.putenv("PWD", xyz)".

> -----Original Message-----
> From: perforce-user-bounces at perforce.com 
> [mailto:perforce-user-bounces at perforce.com] On Behalf Of 
> Looney, James B
> Sent: Tuesday, May 08, 2007 6:07 PM
> To: perforce-user at perforce.com
> Subject: [p4] Invoking Perforce from Python
> 
> Ok, I'm undecided as to whether this is a Python or a Perforce issue,
> either way, I figured out the solution.  Here's what's happening:
> 
> I invoke a Python script that runs Perforce commands (using os.popen)
> I use os.chdir( <some other directory> )
> Then attempt to invoke Perforce again (using os.popen)
> Perforce believes that I'm in the original directory from which the
> Python script was invoked, NOT the directory I changed to from within
> Python.
> 
> The solution?  Use os.putenv( "PWD", os.path.realpath( os.curdir ) ),
> then use os.popen.
> 
> Now, my questions:
> 1) Is it reasonable to expect Perforce to figure out where it is from
> using PWD?  Is there another way? (My coworker made some reference to
> being able to figure out where a program's invoked from without using
> PWD).
> 
> 2) Would this be considered a disconnect in Python?
> 
> -JB
> _______________________________________________
> perforce-user mailing list  -  perforce-user at perforce.com
> http://maillist.perforce.com/mailman/listinfo/perforce-user
> 



More information about the perforce-user mailing list