Basic interaction with another program

Discussion in 'Python' started by ETP, May 4, 2011.

  1. ETP

    ETP Guest

    I have a dos program (run in a window) that I would like to control
    with a script. It needs only text input. For example, I only need to
    tell it:

    L
    u
    100 <cr>
    u

    It will then wait for a file to be created, rename the file, then
    loop. Simple.

    I'd like to run this on Lucid Puppy Linux as it will be implemented on
    a very old laptop, but can probably deal with windows if needed.

    I only need direction on getting Python to interact with another
    program; how do I get it to direct text onto another window?
    ETP, May 4, 2011
    #1
    1. Advertising

  2. ETP

    Matty Sarro Guest

    Look into the pexpect library, it'll make this easy as punch.
    http://www.noah.org/wiki/pexpect


    On Wed, May 4, 2011 at 12:34 PM, ETP <> wrote:
    > I have a dos program (run in a window) that I would like to control
    > with a script.  It needs only text input.  For example, I only need to
    > tell it:
    >
    > L
    > u
    > 100 <cr>
    > u
    >
    > It will then wait for a file to be created, rename the file, then
    > loop.  Simple.
    >
    > I'd like to run this on Lucid Puppy Linux as it will be implemented on
    > a very old laptop, but can probably deal with windows if needed.
    >
    > I only need direction on getting Python to interact with another
    > program; how do I get it to direct text onto another window?
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    Matty Sarro, May 4, 2011
    #2
    1. Advertising

  3. On 2011-05-04, Matty Sarro <> wrote:



    > On Wed, May 4, 2011 at 12:34 PM, ETP <> wrote:
    >> I have a dos program (run in a window) that I would like to control
    >> with a script.


    > Look into the pexpect library, it'll make this easy as punch.


    I don't think pexpect is going to do the OP much good. Quoting from
    the web page:

    "Pexpect does not currently work on the standard Windows Python"

    > http://www.noah.org/wiki/pexpect


    Seriously? Yellow on brown text?

    --
    Grant Edwards grant.b.edwards Yow! When this load is
    at DONE I think I'll wash it
    gmail.com AGAIN ...
    Grant Edwards, May 4, 2011
    #3
  4. ETP

    Ian Kelly Guest

    On Wed, May 4, 2011 at 10:52 AM, Grant Edwards <> wrote:
    > On 2011-05-04, Matty Sarro <> wrote:
    >> On Wed, May 4, 2011 at 12:34 PM, ETP <> wrote:
    >>> I have a dos program (run in a window) that I would like to control
    >>> with a script.

    >
    >> Look into the pexpect library, it'll make this easy as punch.

    >
    > I don't think pexpect is going to do the OP much good. Quoting from
    > the web page:
    >
    >  "Pexpect does not currently work on the standard Windows Python"


    The OP said he was running Linux. I gather the DOS program is being
    run in DOSBox or something similar.
    Ian Kelly, May 4, 2011
    #4
  5. On 2011-05-04, Ian Kelly <> wrote:
    > On Wed, May 4, 2011 at 10:52 AM, Grant Edwards <> wrote:
    >> On 2011-05-04, Matty Sarro <> wrote:
    >>> On Wed, May 4, 2011 at 12:34 PM, ETP <> wrote:
    >>>> I have a dos program (run in a window) that I would like to control
    >>>> with a script.

    >>
    >>> Look into the pexpect library, it'll make this easy as punch.

    >>
    >> I don't think pexpect is going to do the OP much good. Quoting from
    >> the web page:
    >>
    >> ?"Pexpect does not currently work on the standard Windows Python"

    >
    > The OP said he was running Linux.


    My bad. When I saw that he wanted to run a DOS program, I jumped to
    the conclusion he was running Windows and missed the part about puppy
    linux.

    > I gather the DOS program is being run in DOSBox or something similar.


    If it's running in a window as the OP claims, Pexpect still won't work
    since when DOSBox or DOSEmu runs in a window it isn't reading commands
    from a pty but rather from X11. If he can get the program to run on a
    pty (e.g. console or xterm or whatever) rather than in a window, then
    Pexpect should work.

    --
    Grant Edwards grant.b.edwards Yow! Are we wet yet?
    at
    gmail.com
    Grant Edwards, May 4, 2011
    #5
  6. ETP

    Terry Reedy Guest

    On 5/4/2011 12:34 PM, ETP wrote:
    > I have a dos program (run in a window) that I would like to control
    > with a script.


    Look at the subprocess module. You may have to (and be able to) have it
    start up the window program with the dos program as an argument.

    It needs only text input. For example, I only need to
    > tell it:
    >
    > L
    > u
    > 100<cr>
    > u
    >


    You should be able to send this through a pipe connected to the subprocess.


    --
    Terry Jan Reedy
    Terry Reedy, May 4, 2011
    #6
  7. ETP

    ETP Guest

    Thanks everyone.

    I actually ran the program in question using Wine compatibility layer
    and it seemed to work fine.

    Terry, that looks like it could be useful, too. I'll give it a shot
    and let you guys know how it works.
    ETP, May 4, 2011
    #7
    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. Jasper
    Replies:
    8
    Views:
    636
    David
    Jun 12, 2004
  2. Ron Main
    Replies:
    7
    Views:
    312
  3. Rob R. Ainscough
    Replies:
    3
    Views:
    309
    Rob R. Ainscough
    Jun 14, 2005
  4. A. Sinan Unur
    Replies:
    4
    Views:
    114
    Chris Page
    May 11, 2005
  5. Replies:
    3
    Views:
    177
    ChrisHolland@InternetBrands
    Jun 1, 2007
Loading...

Share This Page