---
source: crates/ruff_linter/src/rules/pyupgrade/mod.rs
---
UP022 [*] Prefer `capture_output` over sending `stdout` and `stderr` to `PIPE`
 --> UP022.py:4:10
  |
2 | import subprocess
3 |
4 | output = run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5 |
6 | output = subprocess.run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  |
help: Replace with `capture_output` keyword argument
  |
3 |
  - output = run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
4 + output = run(["foo"], capture_output=True)
5 |
  |
note: This is an unsafe fix and may change runtime behavior

UP022 [*] Prefer `capture_output` over sending `stdout` and `stderr` to `PIPE`
 --> UP022.py:6:10
  |
4 | output = run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
5 |
6 | output = subprocess.run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7 |
8 | output = subprocess.run(stdout=subprocess.PIPE, args=["foo"],  stderr=subprocess.PIPE)
  |
help: Replace with `capture_output` keyword argument
  |
5 |
  - output = subprocess.run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
6 + output = subprocess.run(["foo"], capture_output=True)
7 |
  |
note: This is an unsafe fix and may change runtime behavior

UP022 [*] Prefer `capture_output` over sending `stdout` and `stderr` to `PIPE`
  --> UP022.py:8:10
   |
 6 | output = subprocess.run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 7 |
 8 | output = subprocess.run(stdout=subprocess.PIPE, args=["foo"],  stderr=subprocess.PIPE)
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 9 |
10 | output = subprocess.run(
   |
help: Replace with `capture_output` keyword argument
  |
7 |
  - output = subprocess.run(stdout=subprocess.PIPE, args=["foo"],  stderr=subprocess.PIPE)
8 + output = subprocess.run(capture_output=True, args=["foo"])
9 |
  |
note: This is an unsafe fix and may change runtime behavior

UP022 [*] Prefer `capture_output` over sending `stdout` and `stderr` to `PIPE`
  --> UP022.py:10:10
   |
 8 |   output = subprocess.run(stdout=subprocess.PIPE, args=["foo"],  stderr=subprocess.PIPE)
 9 |
10 |   output = subprocess.run(
   |  __________^
11 | |     ["foo"], stdout=subprocess.PIPE, check=True, stderr=subprocess.PIPE
12 | | )
   | |_^
13 |
14 |   output = subprocess.run(
   |
help: Replace with `capture_output` keyword argument
   |
10 | output = subprocess.run(
   -     ["foo"], stdout=subprocess.PIPE, check=True, stderr=subprocess.PIPE
11 +     ["foo"], capture_output=True, check=True
12 | )
   |
note: This is an unsafe fix and may change runtime behavior

UP022 [*] Prefer `capture_output` over sending `stdout` and `stderr` to `PIPE`
  --> UP022.py:14:10
   |
12 |   )
13 |
14 |   output = subprocess.run(
   |  __________^
15 | |     ["foo"], stderr=subprocess.PIPE, check=True, stdout=subprocess.PIPE
16 | | )
   | |_^
17 |
18 |   output = subprocess.run(
   |
help: Replace with `capture_output` keyword argument
   |
14 | output = subprocess.run(
   -     ["foo"], stderr=subprocess.PIPE, check=True, stdout=subprocess.PIPE
15 +     ["foo"], capture_output=True, check=True
16 | )
   |
note: This is an unsafe fix and may change runtime behavior

UP022 [*] Prefer `capture_output` over sending `stdout` and `stderr` to `PIPE`
  --> UP022.py:18:10
   |
16 |   )
17 |
18 |   output = subprocess.run(
   |  __________^
19 | |     ["foo"],
20 | |     stdout=subprocess.PIPE,
21 | |     check=True,
22 | |     stderr=subprocess.PIPE,
23 | |     text=True,
24 | |     encoding="utf-8",
25 | |     close_fds=True,
26 | | )
   | |_^
27 |
28 |   if output:
   |
help: Replace with `capture_output` keyword argument
   |
19 |     ["foo"],
   -     stdout=subprocess.PIPE,
20 +     capture_output=True,
21 |     check=True,
   -     stderr=subprocess.PIPE,
22 |     text=True,
   |
note: This is an unsafe fix and may change runtime behavior

UP022 [*] Prefer `capture_output` over sending `stdout` and `stderr` to `PIPE`
  --> UP022.py:29:14
   |
28 |   if output:
29 |       output = subprocess.run(
   |  ______________^
30 | |         ["foo"],
31 | |         stdout=subprocess.PIPE,
32 | |         check=True,
33 | |         stderr=subprocess.PIPE,
34 | |         text=True,
35 | |         encoding="utf-8",
36 | |     )
   | |_____^
37 |
38 |   output = subprocess.run(
   |
help: Replace with `capture_output` keyword argument
   |
30 |         ["foo"],
   -         stdout=subprocess.PIPE,
31 +         capture_output=True,
32 |         check=True,
   -         stderr=subprocess.PIPE,
33 |         text=True,
   |
note: This is an unsafe fix and may change runtime behavior

UP022 Prefer `capture_output` over sending `stdout` and `stderr` to `PIPE`
  --> UP022.py:38:10
   |
36 |       )
37 |
38 |   output = subprocess.run(
   |  __________^
39 | |     ["foo"], stdout=subprocess.PIPE, capture_output=True, stderr=subprocess.PIPE
40 | | )
   | |_^
41 |
42 |   output = subprocess.run(
   |
help: Replace with `capture_output` keyword argument

UP022 Prefer `capture_output` over sending `stdout` and `stderr` to `PIPE`
  --> UP022.py:42:10
   |
40 |   )
41 |
42 |   output = subprocess.run(
   |  __________^
43 | |     ["foo"], stdout=subprocess.PIPE, capture_output=False, stderr=subprocess.PIPE
44 | | )
   | |_^
45 |
46 |   output = subprocess.run(
   |
help: Replace with `capture_output` keyword argument

UP022 Prefer `capture_output` over sending `stdout` and `stderr` to `PIPE`
  --> UP022.py:46:10
   |
44 |   )
45 |
46 |   output = subprocess.run(
   |  __________^
47 | |     ["foo"], capture_output=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE
48 | | )
   | |_^
49 |
50 |   # OK
   |
help: Replace with `capture_output` keyword argument
