如何在python中使用cmd命令

时间:2013-10-24 05:11:26

标签: python cmd command

在python

中使用cmd命令的语法是什么?

这是我用过的命令。我希望文件被执行。

self.hosts[1].cmd("python h1.py")

1 个答案:

答案 0 :(得分:1)

如果您只想执行一个文件,请使用Python 3+ Shell:

exec(open("./filename.py").read())

对于命令行,请使用:

chdir "C:\Users\Documents\Project\"
python filename.py

来源:https://stackoverflow.com/questions/13220620/running-python-files-from-command-line