9 fprint(2, "usage: pipefile [-d] [-r command] [-w command] file\n");
14 connect(char *cmd, int fd0, int fd1)
16 switch(rfork(RFPROC|RFFDG|RFREND|RFNOWAIT)){
18 sysfatal("fork %s: %r", cmd);
29 execl("/bin/rc", "rc", "-c", cmd, nil);
30 sysfatal("exec %s: %r", cmd);
36 main(int argc, char *argv[])
40 int fd0, fd1, ifd0, ifd1, dupflag;
50 rcmd = EARGF(usage());
53 wcmd = EARGF(usage());
59 if(argc!=1 || (rcmd==nil && wcmd==nil))
68 ifd0 = open(file, ORDWR);
70 sysfatal("open %s: %r", file);
73 ifd0 = open(file, OREAD);
75 sysfatal("open %s: %r", file);
76 ifd1 = open(file, OWRITE);
78 sysfatal("open %s: %r", file);
81 if(bind("#|", TEMP, MREPL) < 0)
82 sysfatal("bind pipe %s: %r", TEMP);
83 if(bind(TEMP "/data", file, MREPL) < 0)
84 sysfatal("bind %s %s: %r", TEMP "/data", file);
86 fd0 = open(TEMP "/data1", OREAD);
88 sysfatal("open %s: %r", TEMP "/data1");
89 connect(wcmd, fd0, ifd1);
90 fd1 = open(TEMP "/data1", OWRITE);
92 sysfatal("open %s: %r", TEMP "/data1");
93 connect(rcmd, ifd0, fd1);