threads, periodically writing to a process

Fredrik Lundh fredrik at pythonware.com
Fri Sep 30 02:37:13 EDT 2005


Adam Monsen wrote:

>I have a program that, when run, (1) does some task, then (2) prompts
> for input: "Press ENTER to continue...", then repeats for about ten
> different tasks that each take about 5 minutes to complete. There is no
> way to disable this prompt.
>
> How would I go about writing a Python program that would periodically
> (say, every 10 seconds or so) send a carriage return--"\r\n" (or
> whatever the ENTER key sends)--then exit when the subprocess is
> finished?

unless the program you're controlling is really odd, you might as well
send a whole bunch of newlines, and leave it to the other program to
read one at a time as it needs them.

to keep things really simple, you can just do:

import os

f = open("input.txt", "w")
f.write("\n" * 100)
f.close()

os.system("someprogram <input.txt")

os.remove("input.txt")

(changing this to use subprocess and a pipe should be straightforward)

</F> 






More information about the Python-list mailing list