Mutual piping on linux

Posted by user21919 on Super User See other posts from Super User or by user21919
Published on 2012-11-20T12:35:18Z Indexed on 2012/11/20 17:04 UTC
Read the original article Hit count: 283

Filed under:
|

I would like the output of A to be input for B and at the same time the output of B to be the input for A, is that possible?

I tried the naïve thing: creating named pipes for A (pipeA) and B (pipeB) and then:

pipeB | A | pipeA &
pipeA | B | pipeB &

But that does not work (pipeB is empty and switching the order would not help either).

Any help would be appreciated.

Example:

Command A could be compiled form of this C program:

#include <stdio.h>

int main()
{
    printf("0\n");

    int x = 0;
    while (scanf("%d", &x) != EOF)
    {
        printf("%d\n", x + 1);
    }
    return 0;
}

Command B could be compiled form of this C program:

#include <stdio.h>

int main()
{    
    int x = 0;
    while (scanf("%d", &x) != EOF)
    {
        printf("%d\n", x + x);
    }
    return 0;
}

© Super User or respective owner

Related posts about linux

Related posts about pipe