How to automate user input at the command prompt?

Discussion in 'Python' started by gert365@yahoo.com, Jul 21, 2006.

  1. Guest

    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.
    , Jul 21, 2006
    #1
    1. Advertising

  2. Méta-MCI Guest

    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
    Méta-MCI, Jul 21, 2006
    #2
    1. Advertising

  3. Guest

    You may want to look at pexpect:

    http://pexpect.sourceforge.net/

    But I am not sure about its support on windows.

    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.
    , Jul 21, 2006
    #3
  4. Mike Kent Guest

    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.
    Mike Kent, Jul 21, 2006
    #4
  5. Guest

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

    Mike Kent wrote:
    > 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.
    , Jul 21, 2006
    #5
  6. In article <>,
    <> 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.
    Cameron Laird, Jul 21, 2006
    #6
  7. Guest

    Cameron Laird wrote:
    > In article <>,
    > <> 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.
    , Jul 21, 2006
    #7
  8. On 2006-07-21 19:39:52, 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
    Gerhard Fiedler, Jul 21, 2006
    #8
  9. Roger Upole Guest

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

    Roger

    <> wrote in message news:...
    >
    > 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.
    >
    Roger Upole, Jul 22, 2006
    #9
  10. Méta-MCI Guest

    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
    Méta-MCI, Jul 22, 2006
    #10
  11. On Sat, 22 Jul 2006 01:16:36 +0200, "Méta-MCI"
    <> declaimed 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 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

    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
    Dennis Lee Bieber, Jul 22, 2006
    #11
  12. Méta-MCI Guest

    Hi!


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

    - 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
    --
    Michel Claveau
    Méta-MCI, Jul 22, 2006
    #12
  13. Guest

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


    If you happen to have time to explain the possible approaches, it would
    help me tremendously. Thanks.
    , Jul 25, 2006
    #13
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. chrisdude911
    Replies:
    10
    Views:
    135,325
    srk289
    Mar 10, 2009
  2. gaurav kashyap
    Replies:
    2
    Views:
    602
    gaurav kashyap
    Oct 30, 2008
  3. gaurav kashyap
    Replies:
    3
    Views:
    670
    gaurav kashyap
    Oct 31, 2008
  4. Mel
    Replies:
    10
    Views:
    3,092
    Sailaja Appi
    Feb 13, 2009
  5. king
    Replies:
    4
    Views:
    155
    Simon Andrews
    May 30, 2007
Loading...

Share This Page