diff options
author | joeyh <joeyh> | 2006-03-16 17:08:29 +0000 |
---|---|---|
committer | joeyh <joeyh> | 2006-03-16 17:08:29 +0000 |
commit | fa7787ccb87cc8c47f118c65d5bbada602323a68 (patch) | |
tree | 49719c8190a6f444b6d3fbce52dcdabb801e003c | |
parent | 93b625d8288ff9ec522460dac489a170ef130d8c (diff) | |
download | moreutils-fa7787ccb87cc8c47f118c65d5bbada602323a68.tar.gz |
er yeah, let's check in the right stuff
-rwxr-xr-x | pee | bin | 11447 -> 0 bytes | |||
-rw-r--r-- | pee.c | 55 | ||||
-rw-r--r-- | pee.docbook | 77 |
3 files changed, 132 insertions, 0 deletions
Binary files differ @@ -0,0 +1,55 @@ +#include <stdlib.h> +#include <stdio.h> + +/* 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 @@ +<?xml version="1.0" encoding="utf-8"?> + +<!-- + +Copyright 2006 Joey Hess <joey@kitenet.net> + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2 of the License, or (at your +option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--> + +<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook V4.4//EN" +"file:///usr/share/xml/docbook/schema/dtd/4.4/docbookx.dtd" +[]> + +<refentry> + <refentryinfo> + <address> + <email>joey@kitenet.net</email> + </address> + <author> + <firstname>Joey</firstname> + <surname>Hess</surname> + </author> + <date>2006-03-14</date> + </refentryinfo> + + <refmeta> + <refentrytitle>pee</refentrytitle> + <manvolnum>1</manvolnum> + </refmeta> + + <refnamediv> + <refname>pee</refname> + <refpurpose>tee standard input to pipes</refpurpose> + </refnamediv> + + <refsynopsisdiv> + <cmdsynopsis> + <command>pee</command> + <group choice="opt"> + <arg rep="repeat"><replaceable>"command"</replaceable></arg> + </group> + </cmdsynopsis> + </refsynopsisdiv> + + <refsect1> + <title>DESCRIPTION</title> + + <para><command>pee</command> is like <command>tee</command> + but for pipes. Each command is run and standard input is + copied into it, as well as being sent to stdout.</para> + + </refsect1> + + <refsect1> + <title>SEE ALSO</title> + + <para> + <citerefentry> + <refentrytitle>tee</refentrytitle><manvolnum>1</manvolnum> + </citerefentry> + </para> + + </refsect1> +</refentry> |