Get the output from a Popen instance (was: Failed to update the os.environ with subprocess.Popen.)

Hongyi Zhao hongyi.zhao at gmail.com
Sun Apr 3 00:00:54 EDT 2016


On Sun, 03 Apr 2016 13:37:24 +1000, Ben Finney wrote:

>> But, I meet the following errors:
>>
>> ------------
>> Traceback (most recent call last):
>>   File "/home/werner/software/hpc/dft-to-study/jasp/jasp.git/jasp/bin/
>> runjasp.py", line 125, in <module>
>>     os.environ.update(line.partition('=')[::2] for line in output.split
>> ('\0'))
>> AttributeError: 'Popen' object has no attribute 'split'
>> -------------------
> 
> So your problem is nothing to do with “update ‘os.environ’”. I have
> updated the Subject field accordingly.
> 
> The problem you're encountering is only to do with ‘subprocess.Popen’.
> That should make it much easier to search for the documentation to
> understand the problem.
> 
> <URL:https://docs.python.org/3/library/
subprocess.html#subprocess.Popen.stdout>

Thanks a lot, got it. Should be used as follows:

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]

Regards
-- 
.: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.



More information about the Python-list mailing list