How to automate user input at the command prompt?
12 answers - 875 bytes -

I'm working on a scirpt to be used on a windows machine and I need to
automate a user's input on the command prompt. For example I'm using
os.system('mycommand') to excute the commands I want. However some of
these command will prompt for a confirmation of yes or no from user.
Is there anything in python that will allow my script to automate these
input
Another example is let say if i type "format c:\" on the command
prompt it will warn me and ask me to type 'y' to continue. I can use
the os.system to automate the "format c:\" but is there a way to
automate the 'y' input part. I try searching for help on the Interent
but cant seem find any info on how to do this with Python. Can someone
give me some confirmation if what I want to do is possible or not.
Thanks in advance for any help.
No.1 | | 217 bytes |
| 
Hi!
Same problem. I had search, long time, with popenX, with subprocess. I don't
have, actually, any solution
Suggestion: the first which finds prevents the others
@+
Michel Claveau
No.2 | | 1009 bytes |
| 
You may want to look at pexpect:
But I am not sure about its support on windows.
gert365 (AT) yahoo (DOT) com wrote:
I'm working on a scirpt to be used on a windows machine and I need to
automate a user's input on the command prompt. For example I'm using
os.system('mycommand') to excute the commands I want. However some of
these command will prompt for a confirmation of yes or no from user.
Is there anything in python that will allow my script to automate these
input
Another example is let say if i type "format c:\" on the command
prompt it will warn me and ask me to type 'y' to continue. I can use
the os.system to automate the "format c:\" but is there a way to
automate the 'y' input part. I try searching for help on the Interent
but cant seem find any info on how to do this with Python. Can someone
give me some confirmation if what I want to do is possible or not.
Thanks in advance for any help.
No.3 | | 262 bytes |
| 
draghuram (AT) gmail (DOT) com wrote:
You may want to look at pexpect:
But I am not sure about its support on windows.
To the best of my recent investigation, and an email exchange with the
author of pexpect, it is NT supported under Windows.
No.4 | | 394 bytes |
| 
In that case, the P can probably use cygwin's version of python.
pexpect definitely works there.
Mike Kent wrote:
draghuram (AT) gmail (DOT) com wrote:
You may want to look at pexpect:
But I am not sure about its support on windows.
To the best of my recent investigation, and an email exchange with the
author of pexpect, it is NT supported under Windows.
No.5 | | 488 bytes |
| 
In article <1153514279.392848.143930 (AT) 75g2000cwc (DOT) googlegroups.com>,
draghuram (AT) gmail (DOT) com <draghuram (AT) gmail (DOT) comwrote:
>
>In that case, the P can probably use cygwin's version of python.
>pexpect definitely works there.
.
.
.
I suspect there are easier approaches probably won't have time
before Monday to explain. For now, I counsel the original poster
not to be discouraged.
No.6 | | 714 bytes |
| 
Cameron Laird wrote:
In article <1153514279.392848.143930 (AT) 75g2000cwc (DOT) googlegroups.com>,
draghuram (AT) gmail (DOT) com <draghuram (AT) gmail (DOT) comwrote:
>
>In that case, the P can probably use cygwin's version of python.
>pexpect definitely works there.
.
.
.
I suspect there are easier approaches probably won't have time
before Monday to explain. For now, I counsel the original poster
not to be discouraged.
Although I have not find the solution I need yet, thanks to the
suggestions so far I'm actually a bit more optimistic than before that
there might actually be a way to do what I want.
No.7 | | 824 bytes |
| 
2006-07-21 19:39:52, gert365 (AT) yahoo (DOT) com wrote:
Cameron Laird wrote:
>I suspect there are easier approaches probably won't have time
>before Monday to explain. For now, I counsel the original poster
>not to be discouraged.
Although I have not find the solution I need yet, thanks to the
suggestions so far I'm actually a bit more optimistic than before that
there might actually be a way to do what I want.
Until Cameron explains maybe you can work out something with pipes (on
the program's stdin, stdout and stderr). Not sure how that would look like
in Python, though, and it almost for sure won't work with all command line
programs. (There are different ways how a program can read user input.)
Gerhard
No.8 | | 1180 bytes |
| 
If you have the Pywin32 extensions installed, you can use the
win32console module to send keystrokes directly to a command
prompt via WriteConsoleInput.
Roger
<gert365 (AT) yahoo (DOT) comwrote in message news:1153507940.993009.235310 (AT) 75g2000cwc (DOT) googlegroups.com
I'm working on a scirpt to be used on a windows machine and I need to
automate a user's input on the command prompt. For example I'm using
os.system('mycommand') to excute the commands I want. However some of
these command will prompt for a confirmation of yes or no from user.
Is there anything in python that will allow my script to automate these
input
Another example is let say if i type "format c:\" on the command
prompt it will warn me and ask me to type 'y' to continue. I can use
the os.system to automate the "format c:\" but is there a way to
automate the 'y' input part. I try searching for help on the Interent
but cant seem find any info on how to do this with Python. Can someone
give me some confirmation if what I want to do is possible or not.
Thanks in advance for any help.
No.9 | | 392 bytes |
| 
Hi!
I had try with pipes & subprocess. Unfortunaly, when dos-commandline show a
text who question for Yes/No, this text is not available in subprocess/pipe
; =and block!
And then, I can't send "Y" to the stdin
I test with:
MD TT
RD TT/S
(I know, RD TT/S/Q run , but I search another solution).
*sorry for my bad english*
Michel Claveau
No.10 | | 629 bytes |
| 
Sat, 22 Jul 2006 01:16:36 +0200, "MMCI"
<enleverlesX.XmcX (AT) XmclaveauX (DOT) comdeclaimed the following in
comp.lang.python:
Hi!
I had try with pipes & subprocess. Unfortunaly, when dos-commandline show a
text who question for Yes/No, this text is not available in subprocess/pipe
; =and block!
And then, I can't send "Y" to the stdin
There are typically only two output streams from a command line
program. stdout and stderr Some of the S triggered error messages
(abort, retry, fail) might be going to stderr -- so if you were looking
at stdout, you won't see them.
No.11 | | 638 bytes |
| 
Hi!
There are typically only two output streams from a command line program.
stdout and stderr Some of the S triggered error messages
(abort, retry, fail) might be going to stderr -- so if you were looking at
stdout, you won't see them.
- when you use RD TT/S , win show the text "Are-you sure (Y/N)?" on
stdout, and no stderr
- when the text is send, by win, on stdout, there are no RC ; consequently,
subprocess (or popen) don't see anything
- it's possible, with popen4, with subprocess, to merge stdout & stderr in
the same pipe
The problem remain entire.
@-salutations
No.12 | | 624 bytes |
| 
Cameron Laird wrote:
In article <1153514279.392848.143930 (AT) 75g2000cwc (DOT) googlegroups.com>,
draghuram (AT) gmail (DOT) com <draghuram (AT) gmail (DOT) comwrote:
>
>In that case, the P can probably use cygwin's version of python.
>pexpect definitely works there.
.
.
.
I suspect there are easier approaches probably won't have time
before Monday to explain. For now, I counsel the original poster
not to be discouraged.
If you happen to have time to explain the possible approaches, it would
help me tremendously. Thanks.