From: ara.t.howard@... Date: 2006-09-28T11:55:57+09:00 Subject: Re: how to determine if pipe is given On Thu, 28 Sep 2006 gwtmp01@mac.com wrote: > Hmm. Doesn't cron arrange for stdin and stdout to be /dev/null, in which > case the read will simply return EOF, correct? > > I just tried some experiments on Mac OS X and it seems that cron arranges > for stdin to be an empty pipe for cron jobs. > hmmm. you are right. i had to look back at what had given me trouble before - the crux of it was basically this input_on_stdin = not STDIN.tty? infile = if input_on_stdin STDIN.read end so, basically assuming that the user gave input on stdin simply because STDIN was not a tty, which may or may not be true, as in the case where one is running under cron or a system call from a daemon, etc. i guess my point is that 'stdin is not a tty' and 'input was given on stdin' are two orthogonal ideas which, when merged, have bitten me in the past. so that's why i've developed a preference for '-' to signal input on stdin - it's non-ambiguous. > In any case, clearly the program has been invoked incorrectly for that > context (background cron job) and it pretty much doesn't matter what > structure you choose for the command line arguments it is always possible to > screw it up and provide the wrong arguments or plumb the wrong input or > output sources. indeed. > I'm not sure I understand. The OP was suggesting that the program was > designed to read from a pipe, so it really shouldn't care if it was reading > from a tty device, should it? well - that is true. maybe i confused things by making it more general. the only reason i was making a fuss is that it's caused me problems - as i mentioned. probably the noise wasn't worth it. > I think of this like duck typing in Ruby. As long as you can read lines > from the file descriptor and your program is designed to read lines of text, > should you really care if stdin is associated with a file, a pipe, a network > connection, or a tty device? Why not just read and process the data? i think that you are quite right in this case. cheers. -a -- in order to be effective truth must penetrate like an arrow - and that is likely to hurt. -- wei wu wei