Popen(*。exe)如何在新打开的应用程序中模拟Enter?

时间:2018-03-16 17:12:58

标签: python windows

美好的一天。当Popen调用ssms.exe时,我尝试在SQL Server Mgmt Studio中模拟Enter键失败。我需要编码什么?我显然是一个Python新手。 ***目标是按Enter键以便SSMS将“连接”#34;一旦它发布。如果需要,请查看截图非常感谢。

#! python3
from subprocess import Popen
import pyautogui
import time
import os
import signal

## 1. To open SSMS:
proc = Popen("C:\\Program Files (x86)\\Microsoft SQL Server\\130\\Tools\\Binn\\ManagementStudio\\Ssms.exe", shell=True)
print("After Popen")

proc.wait()
print("After wait")

focus = False
print("After focus")

while (focus == False):
    print("In While loop")
    focus = pyautogui.PAUSE = 1
    pyautogui.FAILSAFE = True
    pyautogui.press('enter')
    if (focus == True):
        break

Window Pop-up for SSMS

0 个答案:

没有答案