From: joeyh Date: Thu, 16 Mar 2006 17:08:29 +0000 (+0000) Subject: er yeah, let's check in the right stuff X-Git-Tag: 0.7~1 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa7787ccb87cc8c47f118c65d5bbada602323a68;p=moreutils er yeah, let's check in the right stuff --- diff --git a/pee b/pee deleted file mode 100755 index b4874b7..0000000 Binary files a/pee and /dev/null differ diff --git a/pee.c b/pee.c new file mode 100644 index 0000000..35ad37d --- /dev/null +++ b/pee.c @@ -0,0 +1,55 @@ +#include +#include + +/* Licensed under the GPL + * Copyright (c) Miek Gieben, 2006 + */ + +/* like tee(1), but then connect to other programs using + * pipes _and_ output to standard output + */ + +void +close_pipes(FILE **p, size_t i) +{ + size_t j; + for (j = 0; j < i; j++) + pclose(p[j]); +} + +int +main(int argc, char **argv) { + size_t i, r; + FILE **pipes; + char buf[BUFSIZ]; + + pipes = malloc(((argc - 1) * sizeof *pipes)); + if (!pipes) + exit(EXIT_FAILURE); + + for (i = 1; i < argc; i++) { + pipes[i - 1] = popen(argv[i], "w"); + if (!pipes[i - 1]) { + fprintf(stderr, "Can not open pipe to '%s\'\n", argv[i]); + close_pipes(pipes, i); + + exit(EXIT_FAILURE); + } + } + argc--; + + while(!feof(stdin) && (!ferror(stdin))) { + r = fread(buf, sizeof(char), BUFSIZ, stdin); + for(i = 0; i < argc; i++) { + if (fwrite(buf, sizeof(char), r, pipes[i]) != r) { + fprintf(stderr, "Write error to `%s\'\n", argv[i + 1]); + close_pipes(pipes, i); + exit(EXIT_FAILURE); + } + fwrite(buf, sizeof(char), r, stdout); + } + } + close_pipes(pipes, argc); + + exit(EXIT_SUCCESS); +} diff --git a/pee.docbook b/pee.docbook new file mode 100644 index 0000000..970dc81 --- /dev/null +++ b/pee.docbook @@ -0,0 +1,77 @@ + + + + + + + + +
+ joey@kitenet.net +
+ + Joey + Hess + + 2006-03-14 +
+ + + pee + 1 + + + + pee + tee standard input to pipes + + + + + pee + + "command" + + + + + + DESCRIPTION + + pee is like tee + but for pipes. Each command is run and standard input is + copied into it, as well as being sent to stdout. + + + + + SEE ALSO + + + + tee1 + + + + +