bash - Interchanging two programs inputs and outputs -
the title of question rather misleading, not find better title it.
the rephrased title "i want program x's output program y's input , program y's output program x's input. program x start giving output, while program y start accepting input."
program x stdout --> <program y>stdin stdin --> <program y>stdout
any help?
you can named pipe:
mkfifo xy_pipe ./program_x < xy_pipe | ./program_y > xy_pipe
a regular pipe used connect x's stdout y's stdin.
to connect y's stdout x's stdin create second, named pipe using mkfifo
. named pipe explicit way connect 2 processes way |
does. whenever process writes named pipe blocks until process reads pipe. although xy_pipe
appears file, no data written disk.
example:
$ cat program_x #!/bin/bash echo foo read line && echo "program_x: read '$line'" >&2 $ cat program_y #!/bin/bash read line && echo "program_y: read '$line'" >&2 echo bar $ mkfifo xy_pipe $ ./program_x < xy_pipe | ./program_y > xy_pipe program_y: read 'foo' program_x: read 'bar'
don't forget delete xy_pipe
when you're done!
$ rm xy_pipe
if want see both programs' output on screen can adding tee
mix.
$ mkfifo xy_pipe $ ./program_x < xy_pipe | tee /dev/stderr | ./program_y | tee xy_pipe foo program_x says: foo bar program_y says: bar
Comments
Post a Comment