启动远程桌面连接后,WebApp变得无响应

2024-05-13 01:10:01 发布

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

在创建批处理文件并调用mstc以执行远程桌面连接后,My变得无响应。我本以为这是一个独立的进程,并不以任何方式依赖于我的python scrypt。你知道吗

import os


def rdp_session(server, user, temporary_pass):
    """create Batch file to create .bat file that initiates rdp with variables"""
    rdp = open("rdp_test.bat", "w")
    rdp.write("cmdkey /generic:TERMSRV/"+server+" /user:"+user+" /pass:"+temporary_pass+"\n")
    rdp.write("mstsc /v:"+server+" /admin")
    rdp.close()
    os.system("rdp_test.bat")
    #os.remove("rdp_test.bat") optional, to delete file with creds after executing

我还尝试使用:

subprocess.call("rdp_test.bat")
subprocess.Popen(["rdp_test.bat"])   #doesnt initiate my rdp

我得到了同样的结果。你知道吗

为什么会发生这种情况?我该怎么做才能在RDP运行时保持响应?你知道吗

为了添加一点上下文,我在一个Flask应用程序中有这个函数,我用它来远程连接到不同的机器。当rdp为1时,web应用程序不响应任何命令,当我终止rdp时,我单击的所有内容都会突然执行。你知道吗


Tags: totest应用程序serveroscreatewithpass
2条回答

在阅读了一些关于子进程的内容之后,我发现这些选项都不是立即有效的,因为我不仅需要使用Popen运行子进程,还需要使用Pathname expansion

最后我做了:

subprocess.Popen([os.path.expanduser("My_File.bat")])

expanduser will expand a pathname that uses ~ to represent the current user's home directory. This works on any platform where users have a home directory, like Windows, UNIX, and Mac OS X; it has no effect on Mac OS.

否则,我的应用程序将在关闭rdp会话后运行所有后续命令。这允许我独立于我的web应用程序运行多个子进程,并允许它同时响应

为了让会话继续,您需要派生另一个进程,独立于执行脚本后立即终止的进程。你知道吗

相关问题 更多 >