system command

Jeff Epler jepler at
Thu Jun 13 19:42:59 CEST 2002

On Thu, Jun 13, 2002 at 07:19:48PM +0200, Thor wrote:
> Having this code
>   print "source "+root+".in"
>   os.system("source "+root+".in")
> the script does not run the root+".in" file, but copying and pasting the 
> output form teh 1st line work.. what i'm doing wrong? Thanks in advance

It is not a Python problem.  It is the difference between running
something in a shell or a subshell.  The former is like typing
    source $
    sh -c "source $"
the latter will not make any changes to the environment of the parent
shell.  So setting environment variables, creating aliases, etc., won't
work like you'd hoped.

If you want to have a Python program that changes something in the
parent shell's environment, you have to arrange to execute it in the
shell.  For instance,
    source `python`
    eval `python`


More information about the Python-list mailing list