subprocess.Popen(..., cwd=...) and Makefile $(PWD) don't play nice
bellman at lysator.liu.se
Tue Oct 7 05:24:01 CEST 2008
"Gabriel Genellina" <gagsl-py2 at yahoo.com.ar> writes:
> En Mon, 06 Oct 2008 13:09:26 -0300, Miki <miki.tebeka at gmail.com> escribió:
>> Can anybody explain why Makefile $(PWD) does show the right directory
>> when running under subprocess.Popen(..., cwd=...)
>> For example:
>> [18:07] tmp $cat /tmp/p/Makefile
>> @echo $(PWD)
>> [18:07] tmp $cat t
>> #!/usr/bin/env python
>> from subprocess import Popen
>> Popen(["make"], cwd="/tmp/p")
>> [18:07] tmp $./t
>> The output of the "make" command should have been "/tmp/p" and not "/
> I've tried the equivalent version on Windows and it worked fine.
> And I can't see how make could find the Makefile at /tmp/p if the current
> directory were another one... (?)
The problem is, he is not printing the name of the current working
directory; he is printing the value of the variable $PWD. That is
likely set from the environment by the shell he started the Python
program from, but Python does *not* update to reflect changes to
the working directory.
Use '@pwd' instead of '@echo $(PWD)'.
Thomas Bellman, Lysator Computer Club, Linköping University, Sweden
"Beware of bugs in the above code; I have ! bellman @ lysator.liu.se
only proved it correct, not tried it." ! Make Love -- Nicht Wahr!
More information about the Python-list