正文
python运行windows终端程序
小程序:扫一扫查出行
【扫一扫了解最新限行尾号】
复制小程序
【扫一扫了解最新限行尾号】
复制小程序
其实是用python控制windows里的shell
1.windows有PowerShell,可以通过搜索打开,运行python不需要打开shell
2.用python里的subprocess函数,调用命令
import subprocess
subprocess.run(['dir'],shell=True)
如果一个命令里面有多个字段,比如 cd D:\aa,或者其他
写成
subprocess.run(['cd','D:\aa'],shell=True)
如果有多个参数(多个空格)那就写成
subprocess.run(['参数1','参数2','参数3','参数4'],shell=True)
如果更多参数,以此类推