6 /* Licensed under the GPL
7 * Copyright (c) Miek Gieben, 2006
10 /* like tee(1), but then connect to other programs using
11 * pipes _and_ output to standard output
15 close_pipes(FILE **p
, size_t i
)
19 for (j
= 0; j
< i
; j
++) {
22 ret
|= WEXITSTATUS(r
);
30 main(int argc
, char **argv
) {
35 pipes
= malloc(((argc
- 1) * sizeof *pipes
));
39 for (i
= 1; i
< argc
; i
++) {
40 pipes
[i
- 1] = popen(argv
[i
], "w");
42 fprintf(stderr
, "Can not open pipe to '%s\'\n", argv
[i
]);
43 close_pipes(pipes
, argc
);
50 while(!feof(stdin
) && (!ferror(stdin
))) {
51 r
= fread(buf
, sizeof(char), BUFSIZ
, stdin
);
52 for(i
= 0; i
< argc
; i
++) {
53 if (fwrite(buf
, sizeof(char), r
, pipes
[i
]) != r
) {
54 fprintf(stderr
, "Write error to `%s\'\n", argv
[i
+ 1]);
55 close_pipes(pipes
, argc
);
60 exit(close_pipes(pipes
, argc
));