python - 向 CMD 窗口发送命令?

标签 python windows cmd pyinstaller

我希望能够向 CMD(Windows)发送命令。我需要能够发送多个命令并让它们在 CMD 上运行。

我需要发送的具体命令是:

  • cd "C:\Python27\Scripts"
  • pyinstaller.exe --clean --win-private-assemblies -F --onefile –windowed --icon=app.ico app.py

  • 这很容易吗?

    最佳答案

    非常简单,您可以使用每个命令的子进程模块,也可以将所有命令写入 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')
    

    关于python - 向 CMD 窗口发送命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41065473/

    相关文章:

    Python/Django shell 无法启动

    python - 如何将具有 dtype 的列作为对象转换为 Pandas Dataframe 中的字符串

    windows - 如何在 Windows 上更新 Composer ?

    windows - 使用 CMD 从 Windows 凭据管理器检索密码

    windows - 使用别名运行循环

    python - `__init__` 能做什么而 `__new__` 不能?

    python - 从 Pandas 系列值计数创建 pygal.Bar 图表?

    c++ - Windows Aero 渲染错误

    windows - 如何使用Dragon NaturallySpeaking的高级脚本使扬声器静音?

    cmd - 如何在一行中完成RUNAS命令