3

I want to open a program and interact very briefly with the UI of it. For now I managed to open the program with this line:

subprocess.call([r"C:\Users\path\to\program\program.exe", "first-parameter", "second-parameter"])

The program displays at the start a small warning box with the button "Ok". I would like to simulate a key press "Enter" so that the program moves on. I tried to implement it like it was explained in in this question:

import subprocess
import win32com.client as comctl

wsh = comctl.Dispatch("WScript.Shell")

subprocess.call([r"C:\Users\path\to\program\program.exe", "first-parameter", "second-parameter"])
wsh.AppActivate("program.exe")
wsh.SendKeys("{Enter}") 

The SendKeys() argument was not reached until I closed the program.exe. After I closed the program.exe the "Enter" key got pressed.

Is there a way to interact with the UI of program.exe or do the KeyPress() so it gets reached?

Community
  • 1
  • 1
Nightscape
  • 464
  • 6
  • 19

1 Answers1

1

To NOT wait for you program to exit you need to use subprocess.Popen instead of subprocess.call. More info in python docs here.

Hope this helps!

devdob
  • 1,404
  • 12
  • 13