Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:Sending': 0.07; 'python': 0.07; '>>>>': 0.09; 'subprocess': 0.09; 'sun,': 0.09; 'looked': 0.10; 'am,': 0.14; 'wrote:': 0.14; 'attribute:': 0.16; 'emits': 0.16; 'keystrokes': 0.16; 'stdin': 0.16; 'subject:exe': 0.16; 'idle': 0.19; 'appear': 0.19; 'appropriate': 0.21; 'variable': 0.21; 'header:In-Reply-To:1': 0.22; 'vista': 0.25; 'windows': 0.26; 'chris': 0.27; 'van': 0.27; 'message- id:@mail.gmail.com': 0.28; 'string': 0.29; 'process,': 0.29; 'subject:Windows': 0.29; 'work:': 0.29; 'stops': 0.31; 'does': 0.31; 'import': 0.32; 'to:addr:python-list': 0.32; "i've": 0.33; 'alex': 0.35; 'module.': 0.35; 'think': 0.36; 'received:209.85': 0.37; 'apr': 0.38; 'received:google.com': 0.38; 'but': 0.38; 'to:addr:python.org': 0.39; 'received:209': 0.39; 'takes': 0.40; 'header:Received:5': 0.40; '2011': 0.62; 'become': 0.70; 'dead.': 0.84; 'received:209.85.210.174': 0.84; 'received:mail- iy0-f174.google.com': 0.84; 'running,': 0.91; 'skip:d 50': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=iDLAW0HmPEaJOnIPlkjHjQMeP4xxmXMohFpGE4klx1M=; b=SHd0+qfHB0RcbLZqs4ZlpM2Pi4tH6ePPunE8I5Tdcd5h5e1t1i+mLE+ZvdMfHBjUxM yTBUv6PB7fGlLGBBxL/nb47zJu0ykX/jy5h15zQbkHOHC0MfBa/zZbWYsw1HObenBprO 9k4RAIkxNsPBXQSxK/sNa5ml77+jMfyILK34E= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=wzurc42XPj4oiXg2QKvtkkmzbgiZB8MF7kGNKoz1TmWduUOnqG1jLPxFsEn4DTRK6c gx3JSALKyc9pLMmpwP01mRZigfT4qFDnSxtPaTGz3h3Q/0hLk+coOhyUwNt5tblvsy7y OLOg52E+HFl38zzeX14g/0ktHaADLSE+8m0Bg= MIME-Version: 1.0 In-Reply-To: <4d97536c$0$81483$e4fe514c@news.xs4all.nl> References: <4d97536c$0$81483$e4fe514c@news.xs4all.nl> Date: Sun, 3 Apr 2011 05:52:39 +1000 Subject: Re: Sending keystrokes to Windows exe programs From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 23 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1301773962 news.xs4all.nl 81483 [::ffff:82.94.164.166]:59974 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:2469 On Sun, Apr 3, 2011 at 2:48 AM, Alex van der Spek 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