Q:

Running fifo pipe from single terminal

I was wondering if there is anyway to run two programs using named pipe i.e. fifo, by executing only one program. For example, solution mentioned here [Sending strings between two pipes][1] can it be ran using one terminal only? Is there anyway to call writer.c from reader.c and run the whole program just by running reader.c
EDIT: I removed my code because it had a lot of problems. I was using many functions without having any knowledge about them.
CLOSED.

A:

Use the popen() function to run writer.py from inside your reader program:
https://linux.die.net/man/3/popen
The popen function returns a FILE * which you can then use with any C buffered I/O function.  Eg:
#include <stdio.h>
#include <errno.h>

int main(int argc, char **argv) {

    FILE *fp;
    if((fp = popen("/path/to/writer.py", "r")) == NULL) {
        // handle error in some way
        perror("popen");
        exit(1);
    }

    size_t numbytes;
    char buffer[255];

    // Here we read the output from the writer.py and rewrite it to 
    // stdout.  The result should look the same as if you ran writer.py
    // by itself.. not very useful.  But you would replace this with code
    // that does something useful with the data from writer.py

    while((numbytes = fread(buffer, 1, sizeof(buffer), fp)) > 0) {
        fwrite(buffer, 1, numbytes, stdout);
        // should check for error here
    }

    pclose(fp);
    exit(0);
}

PS: I did not compile or run this program, it is just an example to give you the idea... But it should work.  Also.. I notice you say writer.c in one place and writer.py in another.  It does not matter what language writer is written in.  As long as the program pathname you pass to popen() results in output being written to stdout, it will work.

