Failed to update the os.environ with subprocess.Popen.
Hongyi Zhao
hongyi.zhao at gmail.com
Sun Apr 3 07:24:42 EDT 2016
On Sun, 03 Apr 2016 18:20:31 +1000, Cameron Simpson wrote:
> In particular, you want the subprocess' output. As written, your code
> sets "output" to the Popen object. You actually want to set it to the
> .stdout attribute of that object, which is the output from the
> subcommand.
Based on your above hints, I try to use the following codes:
output = Popen("""
/bin/bash <<EOF
source ~/.profile.d/environment-module-systems/modules.sh
export PATH=$MODULESHOME/../default/bin:$PATH
module add intel/parallel_studio_xe_2015
env -0
EOF
""", shell=True).stdout
But I meet the following error:
Traceback (most recent call last):
File "/home/werner/software/hpc/dft-to-study/jasp/jasp.git/jasp/bin/
runjasp.py", line 138, in <module>
os.environ.update(line.partition('=')[::2] for line in output.split
('\0'))
AttributeError: 'NoneType' object has no attribute 'split'
While the following code will work smoothly:
output = Popen("""
/bin/bash <<EOF
source ~/.profile.d/modules/modules.sh
export PATH=$MODULESHOME/../default/bin:$PATH
module add intel/parallel_studio_xe_2015
env -0
EOF
""", shell=True, stdout=PIPE).communicate()[0]
Any hints on this issue?
Regards
--
.: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
More information about the Python-list
mailing list