【问题标题】:Launch Windows games from shell using Python使用 Python 从 shell 启动 Windows 游戏
【发布时间】:2017-04-11 10:16:58
【问题描述】:

我想从 shell 执行和终止 Windows 游戏。实际需要是在收到特定命令后使用 Python 启动游戏。我尝试使用以下代码启动游戏。

import subprocess

subprocess.Popen("D:/Entertainement/Games/NFS1/speed.exe",shell=False)

当我运行此代码时,游戏启动并停止,没有任何错误。但是当从 Windows 资源管理器中执行时,同样的游戏运行良好。游戏不需要管理员权限,无需管理员权限即可正常运行。

【问题讨论】:

  • python脚本在哪里运行?在 Windows 服务或 Web 应用程序内部或...?
  • 是的。在windows系统里面。作为 websocket 客户端运行
  • 您实际上可以反省Popen 完成后发生的事情。见这里 - stackoverflow.com/questions/25079140/…
  • @Danish 这是我在程序停止后得到的响应。 Traceback (most recent call last): File "C:\Users\devel\Desktop\temp.py", line 3, in <module> proc = subprocess.check_output("D:/Entertainement/Games/NFS1/speed.exe", stderr=subprocess.STDOUT) File "C:\Python27\lib\subprocess.py", line 573, in check_output raise CalledProcessError(retcode, cmd, output=output) CalledProcessError: Command 'D:/Entertainement/Games/NFS1/speed.exe' returned non-zero exit status -1073741819
  • -1073741819 为STATUS_ACCESS_VIOLATION (0xC0000005),表示speed.exe进程无法读取、写入或执行内存地址,因为该地址未分配或受保护。

标签: python windows shell


【解决方案1】:

(代表 OP 发布)

我找到了解决方法。我没有直接启动可执行文件,而是创建了一个快捷方式并使用以下命令启动它。

import subprocess


p = subprocess.Popen("C:\Users\devel\Desktop\speed.exe.lnk",shell=True)
p.wait()
print("Program Exited with return code : "+str(p.returncode))

现在一切正常,我的 Python 程序等待返回码。谢谢大家的回复。

【讨论】:

    猜你喜欢
    • 2018-10-15
    • 2023-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-24
    • 1970-01-01
    • 2015-02-15
    相关资源
    最近更新 更多