I am using Powershell in Windows 10
>>> import os, subprocess
>>> os.listdir('C:\\Program Files') # works
>>> subprocess.run('ls C:\\') # works
>>> subprocess.run('ls C:\\Program Files') # Fails
I have tried forward slashes, escaping, ‘r’ to make a regex, the string enclosed within quotes, and nothing seems to work.
>Solution :
That won’t work in the terminal either. You should quote the file path in the subprocess command:
subprocess.run('ls "C:\\Program Files"')
Everything in those quotes is then read as a single term.