本文介绍了Python执行Windows cmd功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道您可以使用子进程通过Python脚本运行Linux终端命令
I know you can run Linux terminal commands through Python scripts using subprocess
subprocess.call(['ls', '-l']) # for linux
,但是我找不到找到相同方法的方法在Windows上
But I can't find a way to do the same thing on windows
subprocess.call(['dir']) # for windows
是否可以使用Python而无需大量修改?
is it possible using Python without heavy tinkering?
我应该坚持使用老式的批处理吗?文件?
Should I stick to good old fashioned batch files?
推荐答案
尝试一下
import os
os.system("windows command")
ex:针对日期
os.system("date")
这篇关于Python执行Windows cmd功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!