0

I need to send an ENTER Keypress to a Background task without GUI. Sound a bit strange, so here is the explanation:

The Executeable is processing medical Data (MRI and CT DICOM Pictures) and creates automated "pre medical reports". They call it AI. This executeable runs on a headless dedicated Windows 2019 Server in a Datacenter (no Linux Binary available - I asked).

They Company who is responsible for this clusterfu** provides Updates (many Updates). They coded a seperate Updater for the "AI".

When I start the Updater it prompts with "New Version found ..." and "Hit Enter to Continue". I dont want to connect and login to the server everytime they provide an update (Login via OpenSSH tunnel and RDP). So I wrote a short Python script who does the job for me. I spare you the details, because actually knowing that a new Update is available involves a HTML Parser and other cruel things.

The script works fine, except for the part with the ENTER Key. Thats because the Server is headles in a DataCenter.

So I cant use something like pywinauto or some autoit Macros to bring the Window to front and hit Enter, because the Updater starts without a Window in the autologin admin account (another story).

My Idea was to open the Updater with subprocess.popen and generate a Pipe to send the Enter Key. But that didnt work. The updater starts, but did not perform any tasks.

proc = subprocess.Popen([r"C:\Program Files\dicomai\ai.exe"], stdin=PIPE)
time.sleep(5)
proc.communicate(b"\n")

I'am out of Ideas and Workarounds.

Roger012
  • 15
  • 5

2 Answers2

0

I tried this and it worked for me

import subprocess
from subprocess import PIPE
import time

def doit():
    pr = subprocess.Popen([r"C:\Program Files\Mozilla Firefox\firefox.exe"],    stdin=PIPE)
    time.sleep(5)
    import pyautogui
    pyautogui.write("someurl.com\n")

doit()

Try to use this library to take screenshot of your application/desktop for debugging - see documentation for more details https://pyautogui.readthedocs.io/en/latest/screenshot.html

I ran it on the headless server too and it worked fine

jana
  • 166
  • 1
  • 3
0

I tried both Versions:

1) pypi.org/project/keyboard from Ctznkane525

2) pyautogui.write("\n") from jana

Both did the job in a test environment! Thank you!

Roger012
  • 15
  • 5