Using os.popen and os.chdir together
Looney, James B
james.b.looney at lmco.com
Tue May 8 18:43:21 EDT 2007
ok, nevermind. My coworker pointed out part of what's wrong. Guess
I'll need to do more spelunking in my script to figure out what I'm
messing up.
-JB
________________________________
From: python-list-bounces+james.b.looney=lmco.com at python.org
[mailto:python-list-bounces+james.b.looney=lmco.com at python.org] On
Behalf Of Looney, James B
Sent: Tuesday, May 08, 2007 4:17 PM
To: python-list at python.org
Subject: Using os.popen and os.chdir together
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070508/9692029d/attachment.html>
More information about the Python-list
mailing list