Run .exe with subprocess and use pyautogui to send keystrokes

Question:

I am trying to write a python script that will do the following things:

(1) launch a specified .exe file
(2) send a series of keystrokes to that file

I’ve tried using subprocess to open the .exe, and pyautogui to send keystrokes.

import pyautogui as pg
import subprocess
import time

path = 'C: blah blah .exe'

p = subprocess.Popen(path, stdin = subprocess.PIPE_
p.communicate()

pg.write('a bunch of keystrokes')

The issue I am facing is that once subprocess.Popen launches the .exe, the script does not continue unless that .exe program is closed. Is there a way to have the keypresses go through without closing the .exe?

Asked By: dhutama

||

Answers:

Figured it out. Replaced subprocess.Popen with os.startfile(path).

Answered By: dhutama
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.