当前位置: 动力学知识库 > 问答 > 编程问答 >

Running two shell script in the same shell using python scripting

问题描述:

I am calling two shell scripts using python script

My python script: test.py

#!/usr/bin/python

import subprocess

subprocess.Popen(['/usr//bin/tcsh', '-c', 'source set_env.csh'])

subprocess.Popen(['/usrl/bin/tcsh', '-c', 'source ech_env.csh'])

code for set_env.csh

#!/usr/bin/csh

setenv IP_ROOT $cwd

code for ech_env.csh

#!/usr/bin/csh

echo $IP_ROOT

The output will be current working directory path which is store in $cwd . I am getting output as

IP_ROOT:Undefined variable.

Please any one know how can I execute set_env.csh and ech_env.csh in the same shell.

Any suggestion?

网友答案:
subprocess.Popen(['/usr/bin/tcsh', '-c', 'source set_env.csh && source ech_env.csh'])

You need to do everything in a single shell process, so that the environment variables persist between the two scripts.

分享给朋友:
您可能感兴趣的文章:
随机阅读: