Within a script on a *nix machine, I use os.chdir then os.popen, and it
appears to me as though the os.chdir had no effect so far as the
os.popen is concerned.  Why's that?  Here's what I'm doing:

>>> import os
>>> os.path.realpath( os.curdir )
'/home/jlooney'
>>> print os.popen( "echo $PWD" ).readlines()
['/home/jlooney\n']
>>> 
>>> os.chdir( "/tmp" )
>>> os.path.realpath( os.curdir )
'/tmp'
>>> print os.popen( "echo $PWD" ).readlines()
['/home/jlooney\n']
>>> 

You'll notice that initially, the current paths are the same, and
correct.  After I call os.chdir, and try os.popen, it's not in the new
directory.  When I do other things like creating new files, the chdir
did exactly what I expected.  What I don't understand is why os.popen
appears to be special?  How do I change directories within a script and
have popen see that change?

-JB
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to