Cannot find the file specified when using subprocess.call('dir', shell=True) in Python

后端 未结 4 747
北海茫月
北海茫月 2020-12-03 13:59

In a 64-bit system with 32 bit python 2.7 installed I am trying to do the following:

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


        
4条回答
  •  北海茫月
    2020-12-03 14:39

    In case anyone else besides me doesn't see this in the (3.4) docs right away:

    On Windows with shell=True, the COMSPEC environment variable specifies the default shell. 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.

    Note Read the Security Considerations section before using shell=True.

提交回复
热议问题