set environment variable in python script

前端 未结 4 1213
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-27 15:26

I have a bash script that sets an environment variable an runs a command

LD_LIBRARY_PATH=my_path
sqsub -np $1 /homedir/anotherdir/executable
<
4条回答
  •  眼角桃花
    2020-11-27 15:34

    You can add elements to your environment by using

    os.environ['LD_LIBRARY_PATH'] = 'my_path'
    

    and run subprocesses in a shell (that uses your os.environ) by using

    subprocess.call('sqsub -np ' + var1 + '/homedir/anotherdir/executable', shell=True)
    

提交回复
热议问题