equivalent of source <file> in python?

Astan Chee astan.chee at al.com.au
Tue Aug 24 16:50:32 EDT 2010


Thanks for all the help. I think Chris's answer is the one I can use. I 
know its probably better to convert the /etc/setup file into python but 
it'll do for now.
Also, the entire tsch script is just setting up env vars and such; 
various mvs and cps. Not really executing anything.
Thanks again for the help.


Chris Rebert wrote:
> On Tue, Aug 24, 2010 at 12:18 PM, Astan Chee <astan.chee at al.com.au> wrote:
>   
>> Hi,
>> I'm trying to convert my tcsh script to python and am stuck at one part,
>> particularly the part of the script that looks like this:
>>
>> #!/bin/tcsh
>> setenv LSFLOG /var/tmp/lsf_log
>> source /etc/setup
>> unalias cp
>> umask 0
>> env >> ${AFLOG}
>>
>> What is the equivalent of doing this in python2.5?
>>     
>
> I agree with Stefan, but anyway, here's an approximate untested
> literal translation:
>
> import os
> import subprocess
>
> os.environ['LSFLOG'] = '/var/tmp/lsf_log'
> subprocess.check_call(['tcsh', '/etc/setup'])
> os.umask(0)
> out = open(os.environ['AFLOG'], 'a')
> subprocess.check_call(['env'], stdout=out)
> out.close()
>
> Cheers,
> Chris
> --
> http://blog.rebertia.com
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100825/792f4705/attachment-0001.html>


More information about the Python-list mailing list