import subprocess output = subprocess.check_output(['cd', 'C:\\ProgramData', '&&', 'mkdir', 'boot']) print output 

Why does not it work?

  • 2
    What does it mean does not work? Not running the script? The folder is not created? Nothing is written to the standard output (and what did you expect to see there for this command?)? - mkkik
  • Knocks out a traceback error (most recent call last): File "e2e4.py", line 2, in <module> output = subprocess.check_output (['cd', C: \\ ProgramData ',' && ',' mkdir ', 'boot']) File "C: \ Python27 \ lib \ subprocess.py", line 566, in check_output process = Popen (stdout = PIPE, * popenargs, ** kwargs) File "C: \ Python27 \ lib \ subprocess. py ", line 710, in init errread, errwrite) File" C: \ Python27 \ lib \ subprocess.py ", line 958, in _execute_child startupinfo) WindowsError: [Error 2] - Alex Firsov
  • one
    Related issue Subprocess changing directory - mkkik am

1 answer 1

Add a shell=True parameter to the call. It is necessary, when not real executables are called, but interpreter commands.

PS As I understand it, on Windows nothing is given by the transfer of commands in a list, just write the full command line in the call.

  • one
    It is worth mentioning about the undesirable use of shell=True - mkkik