Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to automate user input at the command prompt?

Reply
Thread Tools

How to automate user input at the command prompt?

 
 
gert365@yahoo.com
Guest
Posts: n/a
 
      07-21-2006

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.

 
Reply With Quote
 
 
 
 
Méta-MCI
Guest
Posts: n/a
 
      07-21-2006
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



 
Reply With Quote
 
 
 
 
draghuram@gmail.com
Guest
Posts: n/a
 
      07-21-2006

You may want to look at pexpect:

http://pexpect.sourceforge.net/

But I am not sure about its support on windows.

http://www.velocityreviews.com/forums/(E-Mail Removed) 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.


 
Reply With Quote
 
Mike Kent
Guest
Posts: n/a
 
      07-21-2006

(E-Mail Removed) wrote:
> You may want to look at pexpect:
>
> http://pexpect.sourceforge.net/
>
> 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 NOT supported under Windows.

 
Reply With Quote
 
draghuram@gmail.com
Guest
Posts: n/a
 
      07-21-2006

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

Mike Kent wrote:
> (E-Mail Removed) wrote:
> > You may want to look at pexpect:
> >
> > http://pexpect.sourceforge.net/
> >
> > 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 NOT supported under Windows.


 
Reply With Quote
 
Cameron Laird
Guest
Posts: n/a
 
      07-21-2006
In article <(E-Mail Removed). com>,
(E-Mail Removed) <(E-Mail Removed)> wrote:
>
>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.
 
Reply With Quote
 
gert365@yahoo.com
Guest
Posts: n/a
 
      07-21-2006

Cameron Laird wrote:
> In article <(E-Mail Removed). com>,
> (E-Mail Removed) <(E-Mail Removed)> wrote:
> >
> >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.


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.

 
Reply With Quote
 
Gerhard Fiedler
Guest
Posts: n/a
 
      07-21-2006
On 2006-07-21 19:39:52, (E-Mail Removed) wrote:

> Cameron Laird wrote:
>> 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.


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

 
Reply With Quote
 
Roger Upole
Guest
Posts: n/a
 
      07-21-2006
If you have the Pywin32 extensions installed, you can use the
win32console module to send keystrokes directly to a command
prompt via WriteConsoleInput.

Roger

<(E-Mail Removed)> wrote in message news:(E-Mail Removed) ups.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.
>



 
Reply With Quote
 
Méta-MCI
Guest
Posts: n/a
 
      07-21-2006
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






 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
RAutomation 0.2.1 Released - Automate windows and their controlsthrough user-friendly API with Ruby! Jarmo Pertman Ruby 0 12-17-2010 06:39 PM
automate command line script using perl perlperl Perl Misc 6 06-16-2006 03:38 PM
How to automate a command line test on Linux? srao Perl Misc 5 09-26-2005 09:52 PM
can I use scanf to get input (some times user enters input sometimes not, just hit keyboard)? santa19992000@yahoo.com C Programming 4 09-09-2005 03:38 AM



Advertisments