From: gwtmp01@... Date: 2006-09-29T01:30:40+09:00 Subject: Re: how to determine if pipe is given On Sep 28, 2006, at 12:09 PM, ara.t.howard@noaa.gov wrote: > On Fri, 29 Sep 2006 gwtmp01@mac.com wrote: > >> In both cases if you leave off the '-' the program will report an >> error >> rather than reading and processing the data. The next programmer >> who comes along is going to be very confused by this behavior. > > not if they work on unix! ;-) Huh? That is like saying that grep at the end of a pipeline is expected to be called as: source | grep 'pattern' - instead of simply source | grep 'pattern' >> Can anyone think of a standard Unix program that will *only* read >> from >> stdin in if you give an explicit sentinel as a file argument? > > # > # tarfile on stdout > # > harp:~ > tar -cf - directory > tarfile_on_stdout.tgz Hmm. Tar is a bit of a special case, isn't it? It's default behavior is to access devices in /dev. You don't need -f, if you are using the default devices. > # echo foobar into a gzip of stdin, sending compressed output to > stdout, pipe > # that into another gzip which is decompressing stdin, dump that > output back > # out to stdout > # > harp:~ > echo foobar | gzip - -c | gzip -d - -c > foobar But gzip works just fine without all those extra arguments: echo foobar | gzip > foobar.gz echo foobar | gzip | gzip -d -c > # use image magick's convert command to convert stdin -> stdout > # > harp :~ > convert - - < map.png > map2.png > harp :~ > file map2.png > map2.png: PNG image data, 713 x 569, 8-bit/color RGB, non-interlaced Are you saying that convert < map.png > map2.png doesn't work? If you look back at my posting I said that a program that *requires* the use of '-' would be unusual. I understand why some programs support the '-' notation, which is still a hack if you've got /dev/stdin or /dev/stdout available. Maybe I totally missed the point but I thought the OP was making the requirement that his program would not bother to read from stdin *unless* it saw something special on the command line, which led to your suggestion of the '-'. My point is that the OP's requirement would be very unexpected for the usual Unix programmer.