Windows can't find the file on subprocess.call()

前端 未结 7 1920
孤街浪徒
孤街浪徒 2020-11-27 14:10

I am getting the following error:

WindowsError: [Error 2] The system cannot find the file specified

My code is:

subprocess.         


        
7条回答
  •  星月不相逢
    2020-11-27 14:51

    When the command is a shell built-in, add a 'shell=True' to the call.

    E.g. for dir you would type:

    import subprocess
    subprocess.call('dir', shell=True)
    

    To quote from the documentation:

    The only time you need to specify shell=True on Windows is when the command you wish to execute is built into the shell (e.g. dir or copy). You do not need shell=True to run a batch file or console-based executable.

提交回复
热议问题