I have a program that generates constant output (hcitool lescan
):
CC:41:00:4D:AA:AA Name1
CC:41:00:4D:AA:BB Name2
CC:41:00:4D:AA:CC Name3
I would like to parse this output in Python
constantly, but after few seconds I want to kill the process.
As it has to be terminated manually (by pressing CTRL-C
), I cannot use subprocess.check_value(["prog"])
. Also calling p = subprocess.Popen(["prog"], stdout=subprocess.PIPE)
isn't good, as it orders Popen
to read this to the EOF
. Also, such call hangs the Python
script.
My question is: How can I start a program in Python
(can be limited to Linux
environment) and terminate it after few seconds while gathering it's output (from stdout
)?