0

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?

1 Answer 1

2

The error message in the question does not come from the subprocess. It was generated before the subprocess execution. You cannot capture that error using stderr option.

Make sure there's ding program in the path.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.