简体   繁体   中英

python run csh command

recently, I want to use python script to set environment in linux.This is one line of my code:

p = subprocess.call(['/bin/csh', '-c', "source setup.csh"])

My setup.csh file is below:

add questa10.2b
add ds5-2013.06
setenv MODELSIM modelsim.ini

But when I run my python, it shows that the files have sourced on screen, but it turns out I have to type myself on command line.

How could I solve these problem? Can any one please help me with this?

You're creating a new csh shell as a subprocess and then running your commands inside that shell, which then terminates. The commands do not run in, or affect, the parent shell within which Python is running. When you just run the commands yourself, they affect the current shell.

If you need these settings to persist in your current shell after Python terminates, your best bet in general is to source setup.csh rather than putting it in a Python script. If other child processes of the Python script need your environment variables, you can alter os.environ .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM