4 /* Licensed under the GPL
5 * Copyright (c) Miek Gieben, 2006
8 /* like tee(1), but then connect to other programs using
9 * pipes _and_ output to standard output
13 close_pipes(FILE **p
, size_t i
)
16 for (j
= 0; j
< i
; j
++)
21 main(int argc
, char **argv
) {
26 pipes
= malloc(((argc
- 1) * sizeof *pipes
));
30 for (i
= 1; i
< argc
; i
++) {
31 pipes
[i
- 1] = popen(argv
[i
], "w");
33 fprintf(stderr
, "Can not open pipe to '%s\'\n", argv
[i
]);
34 close_pipes(pipes
, i
);
41 while(!feof(stdin
) && (!ferror(stdin
))) {
42 r
= fread(buf
, sizeof(char), BUFSIZ
, stdin
);
43 for(i
= 0; i
< argc
; i
++) {
44 if (fwrite(buf
, sizeof(char), r
, pipes
[i
]) != r
) {
45 fprintf(stderr
, "Write error to `%s\'\n", argv
[i
+ 1]);
46 close_pipes(pipes
, i
);
51 close_pipes(pipes
, argc
);