system command

Chris Gonnerman chris.gonnerman at newcenturycomputers.net
Thu Jun 13 23:43:52 EDT 2002


----- Original Message -----
From: "Thor" <thor__00 at yahoo.com>


> Daniel Fackrell wrote:
>
> > Assumption: You are referring to the "source" command as provided by the
> > bash shell on some *nix.
> >
> > The man page for bash suggests that you probably want:
> >
> > print "source "+root+".in"
> > os.system("bash "+root+".in")
>
> Changing to bash does the same.. i mean, nothing, no error, just finishes
> the script

Short answer is, no matter how you do it, you can't do it.

The "source" command executes the given file in the *current* shell.  A
Python script, or a Perl script, or for that matter a shell script runs
in a *subshell* and *can not change the parent shell's environment*.
This is a FAQ for shell users somewhere...

BTW this also means that a Python script on Unix/Linux/BSD can't change
the current shell's environment variables either.

Just what, precisely, are you trying to accomplish?  Likely there is some
sort of workaround...

Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net
http://newcenturycomputers.net






More information about the Python-list mailing list