在ssh上运行时,Steam浏览器协议以静默方式失败

2024-10-03 23:25:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图通过ssh连接(进入Win10机器)在我的计算机上启动一个steam游戏。在本地运行时,以下python调用可以工作

subprocess.run("start steam://rungameid/[gameid]", shell=True)

然而,每当我通过ssh连接在交互式解释器中或通过调用目标机器上的脚本来运行它时,我的steam客户端就会突然退出

我在steam日志中没有注意到任何东西,除了Steam\logs\connection_log.txt每次都包含注销和新会话启动。这是而不是在我的机器上本地运行命令时的情况。为什么蒸汽知道该命令的不同来源,为什么这会导致蒸汽连接下降?有人能提出解决办法吗

谢谢


Tags: run命令机器游戏计算机shellstartssh
1条回答
网友
1楼 · 发布于 2024-10-03 23:25:33

Steam可能无法启动应用程序,因为Windows服务(包括OpenSSH服务器)无法访问桌面,因此无法启动GUI应用程序。据推测,Steam不希望在无法与桌面交互的环境中运行应用程序,这就是最终导致Steam崩溃的原因。(无可否认,这只是一个猜测,很难确定当崩溃似乎没有出现在日志或崩溃转储中时到底发生了什么。)

您可以通过domihthis question关于在Windows上通过SSH运行GUI应用程序,看到一个更详细的解释,解释了当服务器作为Windows服务在this answer中运行时,通过SSH启动GUI应用程序失败的原因

多米还提出了一些解决办法。如果这是您的一个选项,最简单的方法可能是手动下载并运行OpenSSH服务器,而不是将服务器作为服务运行。您可以找到最新版本的Win32 OpenSSH/Windows for OpenSSHhere


另一个似乎仍然有效的解决方法是使用schtasks。其思想是创建一个运行命令的计划任务,任务调度器可以访问桌面。不幸的是,如果你不介意至少等到下一分钟,这只是一个可以接受的解决方案schtasks只能将任务精确地安排在一分钟内执行。此外,为了在任何时候都能安全地运行,代码可能应该将任务调度到至少一分钟以后,这意味着等待时间可能在1-2分钟之间

这种方法还有其他缺点。例如,以这种方式监视正在运行的进程可能会更困难。但是,在某些情况下,它可能是一个可接受的解决方案,因此我编写了一些Python代码,可用于使用schtasks运行程序,并提供了一个示例。代码取决于shortuuid包的大小;您需要在尝试该示例之前安装它

import subprocess
import tempfile
import shortuuid
import datetime

def run_with_schtasks_soon(s, delay=2):
    """
    Run a program with schtasks with a delay of no more than
    delay minutes and no less than delay - 1 minutes.
    """
    # delay needs to be no less than 2 since, at best, we
    # could be calling subprocess at the end of the minute.
    assert delay >= 2
    task_name = shortuuid.uuid()
    temp_file = tempfile.NamedTemporaryFile(mode="w", suffix=".bat", delete=False)
    temp_file.write('{}\nschtasks /delete /tn {} /f\ndel "{}"'.format(s, task_name, temp_file.name))
    temp_file.close()
    run_time = datetime.datetime.now() + datetime.timedelta(minutes=delay)
    time_string = run_time.strftime("%H:%M")
    # This is locale-specific. You will need to change this to
    # match your locale. (locale.setlocale and the "%x" format
    # does not seem to work here)
    date_string = run_time.strftime("%m/%d/%Y")
    return subprocess.run("schtasks /create /tn {} /tr {} /sc once /st {} /sd {}".format(task_name,
                                                                                         temp_file.name,
                                                                                         time_string,
                                                                                         date_string),
                          shell=True)
                          
if __name__ == "__main__":
    # Runs The Witness (if you have it)
    run_with_schtasks_soon("start steam://rungameid/210970")

相关问题 更多 >