I am using Python to execute an external program. And I would also like Python to send some keystrokes to the called program to complete auto-login.
The problem is that when I used subprocess.call() to execute the external program, the program got the system focus and the Python script was not able to respond until I closed the external program.
Do you guys have any suggestion about this? Thanks a lot.
Use
subprocess.Popen()
instead of.call()
With
Popen
you also can control stdin, stdout and stderr file descriptors, so you maybe can interact with the external program.Silly example:
Some useful methods:
Many more info in the docs