How to redirect stderr for subprocess module

Dirty Penguin

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?

falsetru

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to redirect stderr in busybox?

From Dev

How to redirect output of a subprocess to a file

From Dev

How to install subprocess module for python?

From Dev

How to redirect stdout and stderr to a file and display stderr to console?

From Dev

How to redirect the raw_input to stderr and not stdout?

From Dev

How to redirect error output to both stdout and to stderr?

From Dev

How to prepend timestamp to the STDERR and redirect to a file

From Dev

How to redirect stderr to a file in a cron job

From Dev

Linux : how to redirect stdout & stderr to logger?

From Dev

How to redirect a part of stderr and stdout to /dev/null

From Dev

How redirect stderr to variable inside if condition? Bash

From Dev

How to redirect stderr in a variable but keep stdout in the console

From Dev

How to redirect stderr to file without any buffer?

From Dev

How can I redirect stdout and stderr with variant?

From Dev

How can I make subprocess get the stdout and stderr in order?

From Dev

How to use a custom file-like object as subprocess stdout/stderr?

From Dev

In Erlang, how can I independently capture stdout and stderr of a subprocess?

From Dev

how do i test subprocess's stdout, stderr in python on windows

From Dev

How to read stdout and stderr and save it all at once with subprocess Popen?

From Dev

How to run Python subprocess and stream but also filter stdout and stderr?

From Dev

How can I read stderr with python if I'm NOT using subprocess?

From Java

How to redirect and append both stdout and stderr to a file with Bash?

From Dev

How to redirect stderr and stdout to different files and also display in terminal?

From Dev

How to redirect stderr to a file and some echos (not stdout) to the same file

From Dev

ksh on BSD style UNIX. How to redirect stderr to tee and a file

From Dev

How do I get bash to redirect stderr into a >( command substitution )?

From Dev

On a Linux system, how would I redirect stdout to stderr?

From Dev

How do I redirect stderr to stdout and vice versa

From Dev

How to redirect stderr/stdout of a Gtk.Window() call in python?

Related Related

  1. 1

    How to redirect stderr in busybox?

  2. 2

    How to redirect output of a subprocess to a file

  3. 3

    How to install subprocess module for python?

  4. 4

    How to redirect stdout and stderr to a file and display stderr to console?

  5. 5

    How to redirect the raw_input to stderr and not stdout?

  6. 6

    How to redirect error output to both stdout and to stderr?

  7. 7

    How to prepend timestamp to the STDERR and redirect to a file

  8. 8

    How to redirect stderr to a file in a cron job

  9. 9

    Linux : how to redirect stdout & stderr to logger?

  10. 10

    How to redirect a part of stderr and stdout to /dev/null

  11. 11

    How redirect stderr to variable inside if condition? Bash

  12. 12

    How to redirect stderr in a variable but keep stdout in the console

  13. 13

    How to redirect stderr to file without any buffer?

  14. 14

    How can I redirect stdout and stderr with variant?

  15. 15

    How can I make subprocess get the stdout and stderr in order?

  16. 16

    How to use a custom file-like object as subprocess stdout/stderr?

  17. 17

    In Erlang, how can I independently capture stdout and stderr of a subprocess?

  18. 18

    how do i test subprocess's stdout, stderr in python on windows

  19. 19

    How to read stdout and stderr and save it all at once with subprocess Popen?

  20. 20

    How to run Python subprocess and stream but also filter stdout and stderr?

  21. 21

    How can I read stderr with python if I'm NOT using subprocess?

  22. 22

    How to redirect and append both stdout and stderr to a file with Bash?

  23. 23

    How to redirect stderr and stdout to different files and also display in terminal?

  24. 24

    How to redirect stderr to a file and some echos (not stdout) to the same file

  25. 25

    ksh on BSD style UNIX. How to redirect stderr to tee and a file

  26. 26

    How do I get bash to redirect stderr into a >( command substitution )?

  27. 27

    On a Linux system, how would I redirect stdout to stderr?

  28. 28

    How do I redirect stderr to stdout and vice versa

  29. 29

    How to redirect stderr/stdout of a Gtk.Window() call in python?

HotTag

Archive