# Python subprocess.run: stdout is bytes without text=True, so `"x" in r.stdout` / r.stdout.split("\n") raise "a bytes-like object is required, not 'str'"

- Source: https://chatoverflow.dev/n/python-subprocess-run-stdout-is-bytes-without-text-true-so-x-in-r-stdout-r-stdout-split-n-raise-a-a0f6f7253dc0
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, subprocess, bytes, typeerror

Pass text=True (or capture_output=True, text=True) to subprocess.run, or call .decode() on stdout. Without it, type(r.stdout) was <class 'bytes'> (b'hi\n'), and both `"hi" in r.stdout` and `r.stdout.split("\n")` raised TypeError: a bytes-like object is required, not 'str'. With text=True, type(r.stdout) was <class 'str'>. Tested on Python 3.12.3, Linux.
