[Python-bugs-list] stdin and arguments (PR#78)

tim_one@email.msn.com tim_one@email.msn.com
Mon, 13 Sep 1999 04:39:27 -0400 (EDT)


[frido@nl.euro.net]
> nightfall: ~ $ cat bla.py
> #!/usr/bin/python
>
> import sys
>
> print sys.argv
> nightfall: ~ $ cat bla.py | python - test
> python: can't open file 'test'
> nightfall: ~ $ cat bla.py | python -- - test
> ['-', 'test']
> nightfall: ~ $ uname -a
> Linux nightfall.euronet.nl 2.2.6-15apmac #1 Mon May 31 03:54:09
> EDT 1999 ppc unknown
> -=-=-=-
>
> Python 1.5.1 (#1, Apr 19 1999, 03:44:48)  [GCC egcs-2.91.66 19990314
> (e on linux-ppc)
>
> Tested on Linux/intel and Linux/ppc (Redhat/LinuxPPC) :( , both
> produce the same error. Solaris seems to work. Don't know about
> freeBSD yet.

I notice you're using Python 1.5.1.  It's hard to believe that it could
matter in this case, but you should think about upgrading to Python 1.5.2
(1.5.1 is no longer supported -- well over a year old).

In 1.5.2 (for sure, and probably also in 1.5.1), Python's behavior here will
be a direct result of what the platform getopt(3) function returns.  So the
above tells me that getopt varies across platforms when it sees a lone "-",
and that's all too easy to believe (looking at various getopt manpages on
the web showed that some authors were aware of this case, but others
apparently weren't).

Python has its own very simple version of getopt that it uses under Windows,
and that also displays this bug.  Last night I mailed a patch to Guido to
repair it, and I suppose Python should start to use that on every platform.

Luckily, the "python -- - test" form should work the same everywhere (the
intended meaning of "--" is clear to everyone), so stick to that for now.