[Tutor] Struggling with os.exec

Roger Merchberger zmerch@30below.com
Thu May 22 13:13:02 2003


Rumor has it that Charlie Clark may have mentioned these words:

>On 2003-05-21 at 20:59:40 [+0200], you wrote:
> > > has a bash (2.03) shell so this is essentially a "posix" question
> > and "cd"
> > > is obviously a built-in command. Is it still possible to call "cd"
> > from
> > > within Python?
> >
> > You might need to do "bash -c 'cd /foo/bar'" or somesuch instead.
> >
> > Just a guess, so probably wrong! :-/
>
>That works without the 's but has seems to call the function "cd" as a
>process in it's own write, ie. with it's own environment variables. What I
>need to do is to be able to change the variables in the parent process, the
>one from which Python is called. I thought this would be easy but it's
>turning into a real challenge... ie., I'm still open for ideas!

AFAIK, it's a "you can't get there from here" problem. I needed to do the 
same thing to 'cd' into a hashed directory structure on our mailserver, 
where the structure info is stored in a PostgreSQL database. My [admittedly 
lameish] hack was this:

I created a program who's output was to just spit out the correct directory 
for the userid, in this case 'cdmail' is the name of my proggie. Call that 
program in backticks to 'cd', like this:

cd `cdmail thisuser`

This will execute the program 'cdmail' and it'll output the correct 
directory - 'cd' will take this info, and cd there.

It's a PITA, but it works [well, mostly;kinda...]

HTH,
Roger "Merch" Merchberger

--
Roger "Merch" Merchberger -- sysadmin, Iceberg Computers
zmerch@30below.com

What do you do when Life gives you lemons,
and you don't *like* lemonade?????????????