Python subprocess with stdout as a string

You can use subprocess.check_output which will redirect stdout to the function call's return value

Something like:

import subprocess

output = subprocess.check_output(['which', 'python'])  
print(output)  

Konpat Preechakul

Read more posts by this author.