From: gwtmp01@... Date: 2006-09-28T13:26:17+09:00 Subject: Re: how to determine if pipe is given On Sep 27, 2006, at 11:55 PM, greg wrote: > I wanted the ability to optionally pipe a file, but the program would > not require a file to be piped or given as an argument. I guess the > answer is that this cannot be done. I can only allow an optional > file > argument, not a pipe. I'm not sure I understand what you mean by 'pipe a file'. Pipes and/or file redirection are arranged by the shell not by the programs running under the shell. The 'normal' way this is handled is: program file # program opens and reads from named file program # program simply reads from standard input In the second case, standard input can be connected to all sorts of things depending how the shell sets up the environment: program program < /from/file source | program In all three cases, the program simply reads from standard input and is oblivious to whether standard input is associated with the terminal, a file, or a pipe. All the 'plumbing' is done by the shell prior to executing the program. Ruby does give you a nice way to read from either standard input or a list of files named on the command line via the special ARGF object. So you simply let ARGF examine the command line arguments and decide if it should get data from STDIN or if should open and read data from the named files. ARGF is a convenience, it isn't doing anything you couldn't do explicitly on your own by processing ARGV yourself. I don't know if that confuses things or not as I don't really understand your objective. Gary Wright