<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7651.59">
<TITLE>Using os.popen and os.chdir together</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<P><FONT SIZE=2 FACE="Arial">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 SIZE=2 FACE="Arial">>>> import os</FONT>
<BR><FONT SIZE=2 FACE="Arial">>>> os.path.realpath( os.curdir )</FONT>
<BR><FONT SIZE=2 FACE="Arial">'/home/jlooney'</FONT>
<BR><FONT SIZE=2 FACE="Arial">>>> print os.popen( "echo $PWD" ).readlines()</FONT>
<BR><FONT SIZE=2 FACE="Arial">['/home/jlooney\n']</FONT>
<BR><FONT SIZE=2 FACE="Arial">>>> </FONT>
<BR><FONT SIZE=2 FACE="Arial">>>> os.chdir( "/tmp" )</FONT>
<BR><FONT SIZE=2 FACE="Arial">>>> os.path.realpath( os.curdir )</FONT>
<BR><FONT SIZE=2 FACE="Arial">'/tmp'</FONT>
<BR><FONT SIZE=2 FACE="Arial">>>> print os.popen( "echo $PWD" ).readlines()</FONT>
<BR><FONT SIZE=2 FACE="Arial">['/home/jlooney\n']</FONT>
<BR><FONT SIZE=2 FACE="Arial">>>> </FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">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 SIZE=2 FACE="Arial">-JB</FONT>
</P>
</BODY>
</HTML>