Communication between two programs on unix

Geoff Gerrietts geoff at gerrietts.net
Wed Jan 22 01:33:20 EST 2003


On Tue, 2003-01-21 at 23:14, morden wrote:
> I want to connect the standard output of the tkinter app to the stdin of 
> the motif app to return results and connect stdout of motif app to the
> input of the tkinter app. Is that doable? I suppose this is what 
> os.popen will do. Right?

The puzzle here is that "standard output" on your motif app and
"standard input" on your tkinter app are neither one likely to be what
you expect. If you start the tkinter app, standard input still reads
from the console, and standard output writes to the console.

If that's what you want -- a character-based input/output stream,
separate from the gui -- then you can proceed. If you're looking to
scrape widgets for their textual content, and auto-insert that into
another widget, you're talking somewhat more advanced X-Windows
sorcery, and I can't help you there.

> Scenario #1: I run my tkinter program with no flags and it
> 	popens motif app it should communicate with

This is true -- it will communicate with either standard input or
standard output on the motif app. Few motif apps would have much to
say on standard out, and wouldn't listen much to stdin, but you could
do it that way.

Take note however that when you popen, your tkinter program is /not/
going to have stdin opened to the target. You'll have a filehandle,
from which you can read.

> Scenario #2: I connect to a remote system using 'cu' from uucp package
> 	and run a unix app there communicating to my tkinter app spawned
> 	with ~+ sequence in cu (that's what you use to run rz/sz over cu 
> session, right?)

I only used uucp once, back in 1996, on recalcitrant SCO boxes.
Someone else will need to help you with this one. This seems like a
suboptimal way to set up a link, though.

My suspicion, however, is that you might implement a "file-like"
object, which, under the covers, uses sz and rz to manage upstream and
downstream connections to your motif app, you could be good to go.

> Scenario #3: I use ssh to get into a remote system and run a unix app 
> there. I have the following question about this scenario: How would I 
> connect input of the tkinter program to the output
> of the motif app and vice versa in this case? Is there any way to tell 
> ssh client to do this or I would have to modify my apps to have support 
> for ssl/tls?

This is actually more ssh magic than anything else. You can handle it
one of two ways -- you can either open the ssh connection inside a
bidirectional pipe, do an "expect"-like wait for the shell prompt,
then fire off your program and start reading the output, OR you can
talk ssh into executing a command as soon as it starts up.

I typically prefer the latter approach: for a vpn app I was working
on, I used:

  ssh -t -e none -c blowfish -o 'Batchmode yes' -l user host sudo pppd

That (-t) forces a pty to be allocated, (-e) turns off escape
characters, (-c blowfish) sets the cipher to blowfish, (-o 'Batchmode
yes') disables password querying in favor of rsa keys, (-l user)
identifies the remote user and (host) host, and when the connection is
made, (sudo pppd) executes the pppd daemon to set up the remote end of
a ppp link. Obviously, the (sudo pppd) trick is the salient bit,
though you'll probably like -t to be on as well.

Now that I've done my best to answer your questions, I'll amend that
it's probably, in many ways, easier to just persuade your programs to
use sockets.

--G.

-- 
Geoff Gerrietts <geoff at gerrietts dot net>     http://www.gerrietts.net/
 "Politics, as a practice, whatever its professions, has always been the 
          systematic organization of hatreds." --Henry Adams





More information about the Python-list mailing list