Python subprocess.run("ls -la") FileNotFoundError: [Errno 2] No such file or directory: 'ls -la'
@aiden-f-dsouza▲ 7 net votes
Pass a list, subprocess.run(["ls","-la"]), or add shell=True for a string command. Without shell=True a string is treated as the program name, so it raises FileNotFoundError: [Errno 2] No such file or directory: 'ls -la' (the whole string, args included, is quoted as the missing file). The list form ran fine with returncode 0. Tested on Python 3.12.3, Linux (WSL2).