On 9/27/06, ara.t.howard / noaa.gov <ara.t.howard / noaa.gov> wrote:

> > apparently in perl, if there is a piped input, '-' will show up
> > automatically in ARGV.  I think I will propose this change to Ruby.
>
> eeeks!  that's is pure __evil__!

Yes I agree with this, but...

> consider  i have many, many programs which do things like
>
>    convert infile outfile
>    convert - outfile       # infile on stdin
>    convert infile -        # outfile on stdout
>    convert - -             # infile on stdin, outfile on stdout
>    convert --infiles=-     # list of infiles on stdin, auto-name outfiles
>
> this is standard unix practice (do a man on gzip, tar, etc).

Standard but by no means universal.  For example the mysql command
doesn't use or like it:

rick@frodo:/public/rubyscripts$ mysql -p -
Enter password:
ERROR 1049 (42000): Unknown database '-'

It either tries to use - as the database name or:

rick@frodo:/public/rubyscripts$ mysql -p depot_development -
mysql  Ver 14.12 Distrib 5.0.22, for pc-linux-gnu (i486) using readline 5.1
...
Usage: mysql [OPTIONS] [database]

It tells me that I don't know the right syntax.

I don't think that it has been mentioned here that one reason for
detecting what's connected to stdin/stdout is useful when a tool
want's to have interactive and non-interactive modes:

Here's mysql in non-interactive mode:

rick@frodo:/public/rubyscripts$ echo "describe products;" | mysql -p
depot_development
Enter password:
Field   Type    Null    Key     Default Extra
id      int(11) NO      PRI     NULL    auto_increment
title   varchar(255)    YES             NULL
description     text    YES             NULL
image_url       varchar(255)    YES             NULL
price   decimal(8,2)    YES             0.00
rick@frodo:/public/rubyscripts$

And here it is in interactive mode:
rick@frodo:/public/rubyscripts$ mysql -p depot_development
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5691 to server version:
5.0.22-Debian_0ubuntu6.06-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> describe products;
+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| id          | int(11)      | NO   | PRI | NULL    | auto_increment |
| title       | varchar(255) | YES  |     | NULL    |                |
| description | text         | YES  |     | NULL    |                |
| image_url   | varchar(255) | YES  |     | NULL    |                |
| price       | decimal(8,2) | YES  |     | 0.00    |                |
+-------------+--------------+------+-----+---------+----------------+
5 rows in set (0.01 sec)

mysql>


Note that it not only puts out prompts but it  changes the output to
be for human rather than computer consumption.


> auto-munging of ARGV is a bad idea imho.

I agree but for other reasons.

As for programs hanging if you do

   program &

Well, that's really a user error, and maybe even not that, maybe I
want to suspend program and then use fg to resume it.

And - doesn't really help this.  I think that it's better in most
cases to solve it the other way around with something like

   program </dev/null &

-- 
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/