Based on the answer provided here, I wanted to save the error as a string:
p = subprocess.Popen(['ding', 'dong'], stderr=subprocess.PIPE, stdout=subprocess.PIPE) output, errors = p.communicate() However, it seems that redirecting stderr is not working:
>>> p = subprocess.Popen(['ding', 'dong'], stderr=subprocess.PIPE, stdout=subprocess.PIPE) Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib64/python2.4/subprocess.py", line 550, in __init__ errread, errwrite) File "/usr/lib64/python2.4/subprocess.py", line 993, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory What is the correct way to capture the error as a string?