[p4] Invoking Perforce from Python

Looney, James B james.b.looney at lmco.com
Tue May 8 16:07:16 PDT 2007


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


More information about the perforce-user mailing list