I am trying the solution given by xApple in this given link: Calling the "source" command from subprocess.Popen
I am calling the shell_source() generator in the script as follows:
def shell_source():
statements
shell_source("./myscript.sh")
when I run the python script, errors I am getting:
./script.sh: 88: Syntax error: end of file unexpected (expecting "then")
Traceback (most recent call last):
File "trial.py", line 20, in <module>
shell_source('./myscript.sh')
File "trial.py", line 17, in shell_source
env = dict((line.split("=", 1) for line in output.split('\x00')))
ValueError: dictionary update sequence element #0 has length 1; 2 is required
but its not working. Am I doing correct? Also, I went through the comments to do editings but not that clear. A snapshot of the execution will help me a lot.
On request, python script(trial.py):
#!/usr/bin/python
import os
import subprocess
import commands
def shell_source(script):
import subprocess, os
pipe = subprocess.Popen("source %s; env" % script, stdout=subprocess.PIPE, executable="/bin/csh" ,shell=True)
output = pipe.communicate()[0]
env = dict((line.split("=", 1) for line in output.splitlines()))
os.environ.update(env)
shell_source('myscript.sh')
myscript.sh:
setenv PROJ_ROOT $PWD
setenv PROJ_OS freebsd
setenv OS freebsd