Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Basic interaction with another program

Reply
Thread Tools

Basic interaction with another program

 
 
ETP
Guest
Posts: n/a
 
      05-04-2011
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?
 
Reply With Quote
 
 
 
 
Matty Sarro
Guest
Posts: n/a
 
      05-04-2011
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 <(E-Mail Removed)> 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
>

 
Reply With Quote
 
 
 
 
Grant Edwards
Guest
Posts: n/a
 
      05-04-2011
On 2011-05-04, Matty Sarro <(E-Mail Removed)> wrote:



> On Wed, May 4, 2011 at 12:34 PM, ETP <(E-Mail Removed)> 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 ...
 
Reply With Quote
 
Ian Kelly
Guest
Posts: n/a
 
      05-04-2011
On Wed, May 4, 2011 at 10:52 AM, Grant Edwards <(E-Mail Removed)> wrote:
> On 2011-05-04, Matty Sarro <(E-Mail Removed)> wrote:
>> On Wed, May 4, 2011 at 12:34 PM, ETP <(E-Mail Removed)> 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.
 
Reply With Quote
 
Grant Edwards
Guest
Posts: n/a
 
      05-04-2011
On 2011-05-04, Ian Kelly <(E-Mail Removed)> wrote:
> On Wed, May 4, 2011 at 10:52 AM, Grant Edwards <(E-Mail Removed)> wrote:
>> On 2011-05-04, Matty Sarro <(E-Mail Removed)> wrote:
>>> On Wed, May 4, 2011 at 12:34 PM, ETP <(E-Mail Removed)> 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
 
Reply With Quote
 
Terry Reedy
Guest
Posts: n/a
 
      05-04-2011
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

 
Reply With Quote
 
ETP
Guest
Posts: n/a
 
      05-04-2011
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.
 
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
interaction with server-side c++ program partialprogressive@gmail.com Javascript 3 06-01-2007 06:25 PM
How to turn a C++ program into a BASIC program ??? Ron Main C++ 7 12-18-2005 03:28 AM
Another basic question: How to call and show one Web Form from another Web Form? Rob R. Ainscough ASP .Net Web Controls 3 06-14-2005 03:56 PM
Basic question - having one program calling another A. Sinan Unur Perl Misc 4 05-10-2005 11:02 PM
Basic c++ and database interaction questions Jasper C++ 8 06-12-2004 10:26 AM



Advertisments