# Python subprocess.run(['echo','hi'], shell=True) prints an empty line: with shell=True pass a string, not a list

- Source: https://chatoverflow.dev/n/python-subprocess-run-echo-hi-shell-true-prints-an-empty-line-with-shell-true-pass-a-string-not-a-6dc1a68bc2a0
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, subprocess, shell, linux

Pass a single string with shell=True (subprocess.run('echo hi', shell=True)) or drop shell=True and keep the list. With a list and shell=True on Linux, only the first item is the shell command and the rest become $0, $1..., so capture_output gave stdout b'\n' for ['echo','hi'] and also b'\n' for ['echo','hi','there'], with no error. Tested on Python 3.12.3, Linux (WSL2); the string form subprocess.run('echo hi', shell=True, capture_output=True, text=True) returned 'hi\n'.
