Persistent Directory Change?

Dave Butler davebutlerREMOVE at hotmail.com
Fri May 31 10:04:41 EDT 2002


Steve,

Thanks for the reply. I suspected this was the case, but wanted to make sure
I was not overlooking something obvious.

One kludgey approach I came up with is:

batfile1.cmd
--------------
python script.py
batfile2.cmd

where the python script generates batfile2.cmd, which contains the 'cd dir'
command.

I always look for a more elegant approach when possible (must be why I like
Python!).

Dave

"Steve Holden" <sholden at holdenweb.com> wrote in message
news:FgLJ8.80380$%u2.65185 at atlpnn01.usenetserver.com...
> "Dave Butler" <davebutlerREMOVE at hotmail.com> wrote ...
> > I have a need for the current directory from a Python script to persist
> > after the script ends. Is this possible? A simple approach such as
> >
> > --------------------
> > import os
> >
> > print os.getcwd()
> > os.chdir(r'f:\temp')
> > print os.getcwd()
> > --------------------
> >
> > does not work. It seems the directory change occurs in the Python
process,
> > but not in the command prompt which called it.
> >
> > I am using Python 2.1 under Windows 2000.
> >
>
> Under Unix things are arranged so that subshells (such as the one used to
> run a Python program) get their own copy of their parent shell's
> environment. Thus changes are explicitly forbidden from propagating to
> parent shells unless you use scripting in the parent shell (such as
>
>     cd `python yourprog.py`
>
> for example, if you can arrange for your program to write the required
> directory out as its only output). Under Windows things are a lot
sloppier,
> but not very consistent. I'd suggest you look at your requirements a
little
> more critically to see what laternatives there might be.
>
> Sorry to be less than positive.
>
> regards
>  Steve
> --
> -----------------------------------------------------------------------
> Steve Holden                                 http://www.holdenweb.com/
> Python Web Programming                http://pydish.holdenweb.com/pwp/
> -----------------------------------------------------------------------
>
>
>
>
>





More information about the Python-list mailing list