---
source: crates/ruff_linter/src/rules/pyupgrade/mod.rs
---
UP022.py:4:10: UP022 [*] Prefer `capture_output` over sending `stdout` and `stderr` to `PIPE`
  |
2 | import subprocess
3 |
4 | output = run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP022
5 |
6 | output = subprocess.run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  |
  = help: Replace with `capture_output` keyword argument

ℹ Unsafe fix
1 1 | from subprocess import run
2 2 | import subprocess
3 3 | 
4   |-output = run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  4 |+output = run(["foo"], capture_output=True)
5 5 | 
6 6 | output = subprocess.run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
7 7 | 

UP022.py:6:10: UP022 [*] Prefer `capture_output` over sending `stdout` and `stderr` to `PIPE`
  |
4 | output = run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
5 |
6 | output = subprocess.run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP022
7 |
8 | output = subprocess.run(stdout=subprocess.PIPE, args=["foo"],  stderr=subprocess.PIPE)
  |
  = help: Replace with `capture_output` keyword argument

ℹ Unsafe fix
3 3 | 
4 4 | output = run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
5 5 | 
6   |-output = subprocess.run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  6 |+output = subprocess.run(["foo"], capture_output=True)
7 7 | 
8 8 | output = subprocess.run(stdout=subprocess.PIPE, args=["foo"],  stderr=subprocess.PIPE)
9 9 | 

UP022.py:8:10: UP022 [*] Prefer `capture_output` over sending `stdout` and `stderr` to `PIPE`
   |
 6 | output = subprocess.run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 7 |
 8 | output = subprocess.run(stdout=subprocess.PIPE, args=["foo"],  stderr=subprocess.PIPE)
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP022
 9 |
10 | output = subprocess.run(
   |
   = help: Replace with `capture_output` keyword argument

ℹ Unsafe fix
5 5 | 
6 6 | output = subprocess.run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
7 7 | 
8   |-output = subprocess.run(stdout=subprocess.PIPE, args=["foo"],  stderr=subprocess.PIPE)
  8 |+output = subprocess.run(capture_output=True, args=["foo"])
9 9 | 
10 10 | output = subprocess.run(
11 11 |     ["foo"], stdout=subprocess.PIPE, check=True, stderr=subprocess.PIPE

UP022.py:10:10: UP022 [*] Prefer `capture_output` over sending `stdout` and `stderr` to `PIPE`
   |
 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 | | )
   | |_^ UP022
13 |
14 |   output = subprocess.run(
   |
   = help: Replace with `capture_output` keyword argument

ℹ Unsafe fix
8  8  | output = subprocess.run(stdout=subprocess.PIPE, args=["foo"],  stderr=subprocess.PIPE)
9  9  | 
10 10 | output = subprocess.run(
11    |-    ["foo"], stdout=subprocess.PIPE, check=True, stderr=subprocess.PIPE
   11 |+    ["foo"], capture_output=True, check=True
12 12 | )
13 13 | 
14 14 | output = subprocess.run(

UP022.py:14:10: UP022 [*] Prefer `capture_output` over sending `stdout` and `stderr` to `PIPE`
   |
12 |   )
13 |
14 |   output = subprocess.run(
   |  __________^
15 | |     ["foo"], stderr=subprocess.PIPE, check=True, stdout=subprocess.PIPE
16 | | )
   | |_^ UP022
17 |
18 |   output = subprocess.run(
   |
   = help: Replace with `capture_output` keyword argument

ℹ Unsafe fix
12 12 | )
13 13 | 
14 14 | output = subprocess.run(
15    |-    ["foo"], stderr=subprocess.PIPE, check=True, stdout=subprocess.PIPE
   15 |+    ["foo"], capture_output=True, check=True
16 16 | )
17 17 | 
18 18 | output = subprocess.run(

UP022.py:18:10: UP022 [*] Prefer `capture_output` over sending `stdout` and `stderr` to `PIPE`
   |
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 | | )
   | |_^ UP022
27 |
28 |   if output:
   |
   = help: Replace with `capture_output` keyword argument

ℹ Unsafe fix
17 17 | 
18 18 | output = subprocess.run(
19 19 |     ["foo"],
20    |-    stdout=subprocess.PIPE,
   20 |+    capture_output=True,
21 21 |     check=True,
22    |-    stderr=subprocess.PIPE,
23 22 |     text=True,
24 23 |     encoding="utf-8",
25 24 |     close_fds=True,

UP022.py:29:14: UP022 [*] Prefer `capture_output` over sending `stdout` and `stderr` to `PIPE`
   |
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 | |     )
   | |_____^ UP022
37 |
38 |   output = subprocess.run(
   |
   = help: Replace with `capture_output` keyword argument

ℹ Unsafe fix
28 28 | if output:
29 29 |     output = subprocess.run(
30 30 |         ["foo"],
31    |-        stdout=subprocess.PIPE,
   31 |+        capture_output=True,
32 32 |         check=True,
33    |-        stderr=subprocess.PIPE,
34 33 |         text=True,
35 34 |         encoding="utf-8",
36 35 |     )

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

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

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