[Tutor] How to interact with the result of subprocess.call()
__peter__ at web.de
Mon Dec 26 05:48:58 EST 2016
Jim Byrnes wrote:
> Is there a way to terminate subprocess and still keep LO open so
> pykeyboard can send it keystrokes from the script?
In theory you can open Libre Office from another thread, wait a moment and
then send it keystrokes from the main thread. I managed to do this with the
However, the procedure is very brittle; while experimenting I managed to
"press" the control key without releasing it afterwards. The interval from
doing it to realizing what was going on to "fixing" it (reboot) was an
from contextlib import contextmanager
kb = pykeyboard.PyKeyboard()
def press_key(key, kb=kb):
print("exiting libreoffice thread")
LONG_ENOUGH = 15 # seconds
# enter text into an existing odt file
filename = "demo.odt"
text = "hello and goodbye"
opener = threading.Thread(target=open_it, args=(filename,))
time.sleep(LONG_ENOUGH) # for libreoffice to start and open the file
print("exiting main thread")
More information about the Tutor