Reputation: 735
I've a program where I've to set the environ variable using setenv but I'm getting an error saying that "/bin/sh: setenv command not found"
but setenv is a built in shell command why is it not working with python subprocess. Can any one help me with this
The code I wrote is:
def ansaunrel(self):
apat = ['setenv ',' ANSA_SRV ','srtia027,srtia028,srtia004']
subprocess.Popen(apat,shell=True)
ansrun='/share/ansa/NOT_RELEASED/14.2.2/ansa64.sh'
subprocess.Popen(ansrun,shell=True)
After setting the env variable I have to run a shell program but the program is not getting started as the environ variable is not set properly. So how can I do this
Upvotes: 4
Views: 3815
Reputation: 48
setenv is a csh builtin, not a bash builtin; you're using the wrong shell if you want to run setenv.
But it doesn't look like you want to run setenv for what you're trying to do. If you want to set the environment for a subprocess, use the env
parameter to Popen:
env = dict(os.environ)
env['ANSA_SRV'] = 'srtia027,srtia028,srtia004'
subprocess.Popen(ansrun, shell=True, env=env)
Upvotes: 3