How to automate user input at the command prompt?

G

gert365

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.
 
M

Méta-MCI

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
 
D

draghuram

In that case, the OP can probably use cygwin's version of python.
pexpect definitely works there.
 
C

Cameron Laird

In that case, the OP can probably use cygwin's version of python.
pexpect definitely works there.
.
.
.
I suspect there are easier approaches--but probably won't have time
before Monday to explain. For now, I counsel the original poster
not to be discouraged.
 
G

gert365

Cameron said:
.
.
.
I suspect there are easier approaches--but 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.
 
G

Gerhard Fiedler

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
 
R

Roger Upole

If you have the Pywin32 extensions installed, you can use the
win32console module to send keystrokes directly to a command
prompt via WriteConsoleInput.

Roger
 
M

Méta-MCI

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 TOTO
RD TOTO/S

(I know, RD TOTO/S/Q run Ok, but I search another solution).

*sorry for my bad english*

Michel Claveau
 
D

Dennis Lee Bieber

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 OS triggered error messages
(abort, retry, fail) might be going to stderr -- so if you were looking
at stdout, you won't see them.
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
M

Méta-MCI

Hi!

(abort, retry, fail) might be going to stderr -- so if you were looking at
stdout, you won't see them.

- when you use RD TOTO/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
 
G

gert365

Cameron said:
.
.
.
I suspect there are easier approaches--but 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top