[Tutor] Running a dos program with python
Armstrong, Richard J.
rarmstro at water.ca.gov
Thu Mar 11 00:06:48 CET 2010
From: srilyk at gmail.com [mailto:srilyk at gmail.com] On Behalf Of Wayne
Werner
Sent: Wednesday, March 10, 2010 3:00 PM
To: Armstrong, Richard J.
Cc: tutor at python.org
Subject: Re: [Tutor] Running a dos program with python
On Wed, Mar 10, 2010 at 4:51 PM, Armstrong, Richard J.
<rarmstro at water.ca.gov> wrote:
The dos program pops up and if I hit the enter key three times then it
runs. How can I add these three "enters" into the script?
I'm not at all sure if this way would work, but you could send the \r\n
through a pipe:
p = subprocess.Popen([file1, file2, file3], stdin=subprocess.PIPE)
p.communicate("\r\n\r\n\r\n") # Three windows line ending sequences.
it also may be possible to add them to the end of the last parameter:
'b.txt\r\n\r\n\r\n'
I don't have much faith that it will work, but you can certainly try!
HTH,
Wayne
Wayne thank you so much!
This worked beautifully:
import subprocess
p = subprocess.Popen([r'c:\shake91.exe', 'FLAC.txt', 'a.txt', 'b.txt'],
stdin=subprocess.PIPE)
p.communicate("\r\n\r\n\r\n") # Three windows line ending sequences.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100310/7528d800/attachment.html>
More information about the Tutor
mailing list