threads, periodically writing to a process

A

Adam Monsen

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?

I guess if I get really into this I'd write something that actually
waits for the subprocess to print "Press ENTER to continue..." to
standard output, *then* sends "\r\n", but extra carriage returns don't
hurt, so the first option is probably viable.

This is probably something that Expect could handle pretty easily, but
I'm just into learning Python for the time being.
 
F

Fredrik Lundh

Adam said:
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top