Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can programs communicate back and forth using pipes?

Tags:

c++

I'm looking at someone's idea for a project. The person wants to have two programs communicate through pipes. Here is my question. Would creating two programs that communicates with one another through pipes on the command line be possible?

like image 911
jax Avatar asked Nov 25 '25 03:11

jax


1 Answers

It would be rather easy to have two programs communicate via pipes and set that up from the command line. E.g. on Linux:

$ mkfifo /tmp/A
$ mkfifo /tmp/B
$ /bin/prog1 --inpipe /tmp/A --outpipe /tmp/B &
$ /bin/prog2 --inpipe /tmp/B --outpipe /tmp/A &
$ wait

Or if the programs just want to communicate through standard input and output:

$ /bin/prog1 < /tmp/A > /tmp/B &
$ /bin/prog2 < /tmp/B > /tmp/A &

Or you can even keep one of the pipes anonymous:

$ /bin/prog1 < /tmp/A | /bin/prog2 > /tmp/A
like image 83
Kerrek SB Avatar answered Nov 27 '25 16:11

Kerrek SB