From: ara.t.howard@... Date: 2006-09-29T02:53:33+09:00 Subject: Re: how to determine if pipe is given On Fri, 29 Sep 2006 gwtmp01@mac.com wrote: >> 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' you are right. i'm just saying it's but not uncommon to sentinal stdin via '-'. > 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. for output yes. for input no. > But gzip works just fine without all those extra arguments: > > echo foobar | gzip > foobar.gz > echo foobar | gzip | gzip -d -c that is true. i'm merely pointing out the standardness of '-', not it's required-ness... >> # 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? yes. harp:~ > file map.png map.png: PNG image data, 640 x 480, 8-bit colormap, non-interlaced harp:~ > convert < map.png > map2.png harp:~ > file map2.png map2.png: ASCII English text note that the output file is the output of --help. note the last 5 lines ;-) harp:~ > tail -5 map2.png By default, the image format of `file' is determined by its magic number. To specify a particular image format, precede the filename with an image format name and a colon (i.e. ps:image) or specify the image type as the filename suffix (i.e. image.ps). Specify 'file' as '-' for standard input or output. > 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. i personally wouldn't quite call it a hack tough, curl, wget, tar, gzip, image magic - these are all commands which will compile on many oses. some of them even compile on windows! ;-) i suppose it just depends on what kinds of command one is using and in what kinds of environments with respect to whether one finds '-' odd or not. i run many things under cron and in a clustered environment and have grown accustomed to it. i admit it's not common for tty usage. > 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. sorry. you are right here of course. i'm going to bow out of this thread - the last thing i'll say is that i've been bitten by automatic reading of stdin and, even though many unix standards do it (cat, gzip, etc) i've noticed newer and more complicated, eg. curl, programs seemed to have shyed away from it. i have too, just because it's bitten me with hung programs in a clustered environment (no tty). anyhow - this horse is dead! ;-) kind regards. -a -- in order to be effective truth must penetrate like an arrow - and that is likely to hurt. -- wei wu wei