From: David King Landrith Date: 2003-07-29T14:26:23+09:00 Subject: Re: How do I tell when my CLI output is piped? Works perfect! Thanks! On Tuesday, July 29, 2003, at 12:54 AM, Harry Ohlsen wrote: > David Landrith wrote: > >> ... I'd like to be able to automatically sense when the output is >> being piped to somewhere else, so that I can automatically make the >> report switch to a tab delimited format a la the mysql command line >> client. > > In C, this is normally done using the standard library routine > isatty(file_descriptor) which returns non-zero when output is going to > a terminal. > > Looking at the documentation for IO in pickaxe, there is an isatty() > method. > > So, I would imagine you can do something like (completely untested!) > ... > > if $stdout.isatty > puts "Going to a terminal" > else > puts "Going somewhere else" > end > > Note that this would also include if you redirect the output to a file. > > Hope that helps. > > Harry O. > > > ------------------------------------------------------- David King Landrith (w) 617.227.4469x213 (h) 617.696.7133 Generic quotes offend nobody. --Unknown ------------------------------------------------------- public key available upon request