<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Using os.popen and os.chdir together</TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.3059" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left>
<DIV dir=ltr align=left><SPAN class=885084222-08052007><FONT face=Arial 
color=#0000ff size=2>ok, nevermind.  My coworker pointed out part of what's 
wrong.  <SPAN class=000114322-08052007>G</SPAN>uess I'll need to do 
more spelunking in my script to figure out what I'm messing 
up.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=885084222-08052007><FONT face=Arial 
color=#0000ff size=2>-JB</FONT></SPAN></DIV></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> 
python-list-bounces+james.b.looney=lmco.com@python.org 
[mailto:python-list-bounces+james.b.looney=lmco.com@python.org] <B>On Behalf Of 
</B>Looney, James B<BR><B>Sent:</B> Tuesday, May 08, 2007 4:17 PM<BR><B>To:</B> 
python-list@python.org<BR><B>Subject:</B> Using os.popen and os.chdir 
together<BR></FONT><BR></DIV>
<DIV></DIV><!-- Converted from text/rtf format -->
<P><FONT face=Arial size=2>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:</FONT></P>
<P><FONT face=Arial size=2>>>> import os</FONT> <BR><FONT face=Arial 
size=2>>>> os.path.realpath( os.curdir )</FONT> <BR><FONT face=Arial 
size=2>'/home/jlooney'</FONT> <BR><FONT face=Arial size=2>>>> print 
os.popen( "echo $PWD" ).readlines()</FONT> <BR><FONT face=Arial 
size=2>['/home/jlooney\n']</FONT> <BR><FONT face=Arial size=2>>>> 
</FONT><BR><FONT face=Arial size=2>>>> os.chdir( "/tmp" )</FONT> 
<BR><FONT face=Arial size=2>>>> os.path.realpath( os.curdir )</FONT> 
<BR><FONT face=Arial size=2>'/tmp'</FONT> <BR><FONT face=Arial 
size=2>>>> print os.popen( "echo $PWD" ).readlines()</FONT> <BR><FONT 
face=Arial size=2>['/home/jlooney\n']</FONT> <BR><FONT face=Arial 
size=2>>>> </FONT></P>
<P><FONT face=Arial size=2>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?</FONT></P>
<P><FONT face=Arial size=2>-JB</FONT> </P></BODY></HTML>