[Tutor] Program to Simulate Keystrokes

Wayne srilyk at gmail.com
Tue Aug 4 20:00:01 CEST 2009


On Tue, Aug 4, 2009 at 12:43 PM, Megan Land <mland at us.ibm.com> wrote:

>  Hi,
>
> I'm working on a python script to automate a program we run at work. The
> program is run from one command. The only problem is that it asks you to hit
> enter to continue after it runs. Is there a way I can do this?
>
> If at all possible I need a program that will work on Windows and Linux (I
> know a tall order). I'm trying to keep this simple but if I have to use two
> different programs I will.
>
I just tested and this seems to work:

import subprocess
p = subprocess.Popen(['python', 'asdf.py'], stdout=subprocess.PIPE,
stdin=subpro
cess.PIPE)
p.stdin.write('\r\n')
print p.stdout.readlines()

- the contents of asdf.py are just these:

raw_input("Press enter to continue")
print "Works!"

HTH!
-Wayne, who just learned a little something about the subprocess module
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090804/68aaf62e/attachment.htm>


More information about the Tutor mailing list