Re: Reading and Writing to existing appl with PYTHON

Steven D. Majewski (sdm7g@elvis.med.virginia.edu)
Fri, 18 Mar 1994 13:59:39 -0500

In article <CMrx9u.CBw@ss3.magec.com>, in comp.lang.misc, you write:
>
>I'm trying to write a python application that rides on top of an existing
>application. I need to establish bi-directional communications with the
>old application.
>
>Anyone done this before?
>

I'm not sure what exactly you mean by "rides on top of" and
"communication" .

Do you mean having python fork and exec the existing app, writing
and reading thru pipes ?

Or do you mean embedding the existing code in the Python interpreter ?

( Or something else? )
Both of the above can be done.

The first I have done with some limited success. ( and some
failure ! ) I've gotten this to work with some progs, but
with others, it fails in various ways. With prog == None,
it should talk to another python process, but I get errors
from that process when I try to send it a simple python
command or expression.
( via. posix.write( f[1], '1 + 2\n' ), for example. )

import posix
import sys

def test( prog, *args ):
p = posix.pipe()
pid = posix.fork()
if pid : return p + (pid,)
posix.dup2( p[0], sys.stdin.fileno() )
posix.dup2( p[1], sys.stdout.fileno() )
if prog : return posix.execv( prog, args )

A vote is pending to create a comp.lang.python newsgroup.
In the meantime, you might want to send your questions to
the python mailing list ( python-list@cwi.nl ).

I am CC-ing this message to the list - maybe someone there
will have some additional advice for YOU, or some comments
on why MY code doesn't always work.

In some simple tests, it worked for 'bc', it didn't work
at all for 'tr', and just forking another python image
gave syntax errors when it read the string. I have heard
that there are often sync problems with full duplex pipes -
I have also run into that, but THESE are different problems.
( One way communication with posix.popen() is trivially easy.)

- Steve Majewski (804-982-0831) <sdm7g@Virginia.EDU>
- UVA Department of Molecular Physiology and Biological Physics