Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #2469

Re: Sending keystrokes to Windows exe programs

References <4d97536c$0$81483$e4fe514c@news.xs4all.nl>
Date 2011-04-03 05:52 +1000
Subject Re: Sending keystrokes to Windows exe programs
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.139.1301773961.2990.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Apr 3, 2011 at 2:48 AM, Alex van der Spek <zdoor@xs4all.nl> wrote:
> I can start a windows program on Vista with:
>
>>>> import subprocess
>>>> dva=subprocess.Popen(DVAname,stdin=subprocess.PIPE)
>
> Unfortunately sending keystrokes with communicate() does not appear to work:
>
>>>> dva.communicate('F2')
>
> this does not produce any result but it does make IDLE become really idle.

I've just looked over the Python subprocess module. Is your subprocess
(named by the variable DVAname) one which takes key names on STDIN and
emits the appropriate keys?

dva.communicate('F2') will send the two-character string "F2" to the
STDIN of the process, and then wait for process termination. That's
why IDLE stops dead. If you want to send it a string and then keep
running, I think you want to use the stdin attribute:
dva.stdin.write('F2')

Chris Angelico

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Sending keystrokes to Windows exe programs "Alex van der Spek" <zdoor@xs4all.nl> - 2011-04-02 18:48 +0200
  Re: Sending keystrokes to Windows exe programs Chris Angelico <rosuav@gmail.com> - 2011-04-03 05:42 +1000
  Re: Sending keystrokes to Windows exe programs Chris Angelico <rosuav@gmail.com> - 2011-04-03 05:52 +1000

csiph-web