I'm trying to execute a bash script from inside python using the subprocess
module. The problem is that this bash script relies on many environment variables that are set in my .bashrc
file. What I want is for python subprocess to exactly replicate the environment that is setup when I launch a terminal window. So far I tried:
p = subprocess.Popen(args=['my-script.sh', '--additional_args'], stdout=subprocess.PIPE, env=os.environ.copy(), shell=True)
output_buffer, return_code = p.communicate()
But then read somewhere that even after doing shell=True
, the .bashrc
file is still not loaded, and that i should try something like this:
p = subprocess.Popen(args=['/bin/bash', '-i', '-c', 'my_script.sh', '--additional_args'], stdout=subprocess.PIPE)
output_buffer, return_code = p.communicate()
But with this function call, I get this error:
tput: No value for $TERM and no -T specified
bash: cannot set terminal process group (2071): Inappropriate ioctl for device
bash: no job control in this shell