1.2 Public Domain    
3.0/5 14


Pip is a tool that can make any program a filter.




Pip is a tool that can make any program a filter.

Some programs (often those from a non-Unix background) don't read input from stdin, nor write to stdout. Instead, they make you specify an 'input file' and an 'output file' on the command line. At least most Unix programs that do this let you use the special filename '-' to mean stdin or stdout, but there are some programs that don't recognize this convention.

Sometimes this is for technical reasons, because the input needs to be seekable. Sometimes it is because the author didn't think it would be useful and is probably a Pascal sympathizer. But in any case, it is annoying not to be able to use such programs in pipelines.

Pip fixes this problem. It wraps such programs and lets you give filenames of '-' as you would with any other. However pip doesn't know whether '-' should mean stdin or stdout, so you must tell it with the -i, -o, or -b switches. Pip also provides -I and -O for programs which can use stdin and stdout but require them to be seekable.

For example, to convert the program 'stupid', which takes an input filename and an output filename, to be a filter:

pip -io stupid - -

To pipe a C program through the compiler (if for any reason you needed to do such a thing):

pip -io gcc -.c -o -

In this case, the temporary input filename given to gcc will end in '.c'. And to pipe some text through emacs, giving the user the chance to edit it:

pip -b emacs -

An example of the -I switch, to buffer stdin into a file so that dvips's 'filter' mode (which expects a seekable stdin) can use it:

pip -I dvips -f

See the manual page for more.


Although pip is general enough for most uses, it won't handle TeX and LaTeX properly. For this there is a separate program pip_latex which is a wrapper for LaTeX. It accepts LaTeX source on standard input and writes a DVI file to standard output - or you can install it as pip_tex if you don't use LaTeX. It tries to do something sensible with TeX's error messages - see the documentation at the start of the script. For example:

cat filename.tex | pip_latex | pip -i xdvi -


This is a special-purpose wrapper for the latex2html program. It reads LaTeX source from stdin and tries to convert it to HTML written to stdout.

Pip versus /dev/stdin and /dev/stdout

On most Unices, you can often get the same effect as pip by using /dev/stdin and /dev/stdout (thanks to Daniel Biddle for pointing this out). However although this works for programs which read and write sequentially, and gets you the normal pipeline laziness in such situations, it won't work for those that want to do random-access file operations on their input or output.

Try running your program with /dev/stdin or /dev/stdout; if it fails in some strange manner, try again using pip, which should work with just about anything. Also pip works on Windows, where /dev/std* don't exist.




As for Perl modules:

% perl Makefile.PL PREFIX=/usr/local # or whatever
% make
% make test
% make install
Last updated on January 23rd, 2008

#program filter #latex to html #Perl module #filter #stdin #stdout #latex

0 User reviews so far.