You are not logged in.

#1 2009-06-21 11:25:04

The_Air_Penguin
Member
Registered: 2008-12-04
Posts: 12

Making programs interact

I was wondering what would be the simplest way to make 2 programs interract through standard I/O. I mean something like a two-way pipe: first program outputs something, second one reads it and outputs something back to the first one... The idea is to automate evaluation of solutions to some simple user interactive problems.

Has anyone done something like this? Could I do it with simple Bash or should I use something more powerful like Python or even C++? Those are the three languages I can use.

Offline

#2 2009-06-21 11:50:03

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,094

Re: Making programs interact

Unix sockets?


Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

#3 2009-06-22 17:30:09

The_Air_Penguin
Member
Registered: 2008-12-04
Posts: 12

Re: Making programs interact

Mr.Elendig wrote:

Unix sockets?

That sounded far too complicated for what I was going for, so I googled it a bit and found out how great bash named pipes are. Still, I was messing around with it for a lot of time and got nowhere. Then I got lucky and found a post from some forum where this guy had a brilliantly simple solution for connecting two commands (or functions, programs...) with one standard pipe and one named pipe:

fifo='/tmp/myfifo'
mkfifo $fifo
first <$fifo | second >$fifo
rm $fifo

I think I'm getting more and more in love with bash!

Offline

#4 2009-06-22 18:01:51

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Making programs interact

A fifo has a delay though, right?

Offline

#5 2009-06-22 18:09:24

The_Air_Penguin
Member
Registered: 2008-12-04
Posts: 12

Re: Making programs interact

I don't know. What exactly do you mean? I am new to bashing, so it's quite possible that there's some problem I didn't notice, but this solution seems to be working great for now.

Offline

#6 2009-06-22 19:25:19

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Making programs interact

I forgot what it was exactly, the delay was probably just coming from tail -f.

Offline

Board footer

Powered by FluxBB