[英]Send commands to CMD window?
I'm looking to be able to send commands to the CMD (windows). 我希望能够将命令发送到CMD(Windows)。 I need to be able to send multiple commands and have them run on the CMD.
我需要能够发送多个命令并使它们在CMD上运行。
The specific commands I need to send are: 我需要发送的特定命令是:
cd "C:\\Python27\\Scripts"
pyinstaller.exe --clean --win-private-assemblies -F --onefile –windowed --icon=app.ico app.py
Is this easily possible? 这容易吗?
Very simple, you can either user the subprocess module for each command, or you can write all the commands to a bat file and execute that. 非常简单,您可以使用每个命令的子流程模块,也可以将所有命令写入bat文件并执行。
import os
script = '''
cd "C:\Python27\Scripts"
pyinstaller.exe --clean --win-private-assemblies -F --onefile –windowed --icon=app.ico app.py
'''
with open('tmpscript.bat') as file_:
file_.write(script)
# either system or subprocess will work here
os.system('tmpscript.bat')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.