Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #30024

Re: Command line arguments

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Command line arguments
Date 2013-01-12 10:22 -0800
Organization None to speak of
Message-ID <ln4nimjm70.fsf@nuthaus.mib.org> (permalink)
References (5 earlier) <486a1ce3-650e-4c93-81b3-c42e6cbee62e@googlegroups.com> <kcppe4$orb$1@speranza.aioe.org> <gw1Is.680$lO4.445@fx15.fr7> <kcqo6g$78h$1@dont-email.me> <3ncIs.609$xr.412@fx16.fr7>

Show all headers | View raw


"BartC" <bc@freeuk.com> writes:
> "James Kuyper" <jameskuyper@verizon.net> wrote in message 
> news:kcqo6g$78h$1@dont-email.me...
>> On 01/11/2013 06:46 PM, BartC wrote:
>> ...
>>> The most flexible approach would have been to supply a raw, unprocessed
>>> command line to a C program. Then it would work exactly the same way as
>>> every subsequent line of input.
>>>
>>> With a library function to chop it up into parameters, and perhaps expand
>>> them, if that is desired.
>>>
>>> In fact WinMain() works exactly like that (apart from having such a 
>>> function
>>> as I suggested).
>>
>> Your first message on this thread implies that you never knew about this
>> feature until yesterday, which implies that you must be very new to
>> unix-like systems.
>
> I was using Windows, and the problem manifested itself under Windows. I 
> assumed it was feature of the C runtime, and that it would be the same under 
> Linux. It turns out it *was* done by the C runtime in this case.

So a program compiled on and for Windows with gcc (MinGW?) implicitly
invokes some C runtime routine that expand wildcards that appear
on the command line?

That's consistent with what I'm seeing.  On Windows 7, a C program
compiled with MinGW and invoked with *.c on the command line sees a
list of file names as separate elements of the argv array; a similar
program compiled with MS Visual C++ 2010 sees a single argument,
the string "*.c".

The difference in behavior does seem a little odd.  An alternative
would have been for MinGW to fit in with the usual Windows behavior,
where individual programs are responsible for expanding (or not
expanding) wildcards.  I think the idea behind MinGW is to provide
a minimal POSIX-like environment under Windows, not to provide a
gcc compiler integrated into the Windows environment.  (There are
likely options to make it do the latter; I haven't looked into it.)

> But I've also been using the C runtime for years in the background of other 
> projects, and I'd never seen it  behave that way. So it was specific to gcc 
> which I've switched to recently.

The C runtime library is not part of gcc; gcc is just the compiler
(it can also invoke the linker).  Apparently the behavior you're
seeing is the result of the way the MinGW developers have chosen
to integrate the gcc compiler, the Microsoft C runtime library,
and whatever other components they've added.

Since you seem to be happier with the Windows behavior (where
programs are responsible for their own wildcard handling) than
with the POSIX behavior (where wildcards are expanded before main()
starts running), why are you using MinGW in the first place?

If you want to write programs that run on POSIX systems (Linux,
Unix, Cygwin, etc.), I advise you *not* to try to override the way
wildcards are expanded.  Even if you managed to do it, the resulting
behavior would be extremely counterintuitive to your users, who are
likely to be as uncomfortable with wildcards *not* being pre-expanded
as you are with them being pre-expanded.  If I have a copy of your
program and I need to pass the string "*.c" to it as an argument,
I know exactly how to do it.  Think about what behavior your users
are going to expect, not just what you personally prefer.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Command line arguments "BartC" <bc@freeuk.com> - 2013-01-10 20:58 +0000
  Re: Command line arguments pu <uselpa.list@gmail.com> - 2013-01-10 22:02 +0100
    Re: Command line arguments pu <uselpa.list@gmail.com> - 2013-01-11 14:43 +0100
      Re: Command line arguments glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-11 19:10 +0000
  Re: Command line arguments Willem <willem@turtle.stack.nl> - 2013-01-10 21:02 +0000
    Re: Command line arguments "BartC" <bc@freeuk.com> - 2013-01-10 21:34 +0000
      Re: Command line arguments Jorgen Grahn <grahn+nntp@snipabacken.se> - 2013-01-10 22:02 +0000
      Re: Command line arguments Greg Martin <greg@softsprocket.com> - 2013-01-10 14:13 -0800
        Re: Command line arguments "BartC" <bc@freeuk.com> - 2013-01-10 22:32 +0000
          Re: Command line arguments Lew Pitcher <lpitcher@teksavvy.com> - 2013-01-10 17:49 -0500
            Re: Command line arguments BruceS <bruces42@hotmail.com> - 2013-01-10 16:05 -0700
              Re: Command line arguments Lew Pitcher <lpitcher@teksavvy.com> - 2013-01-10 18:15 -0500
              Re: Command line arguments JohnF <john@please.see.sig.for.email.com> - 2013-01-11 06:54 +0000
                Re: Command line arguments Shao Miller <sha0.miller@gmail.com> - 2013-01-11 02:26 -0500
                Re: Command line arguments glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-11 09:02 +0000
                Re: Command line arguments Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2013-01-11 11:17 -0700
                Re: Command line arguments Shao Miller <sha0.miller@gmail.com> - 2013-01-11 13:20 -0500
                Re: Command line arguments Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2013-01-11 13:13 -0700
                Re: Command line arguments glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-11 19:22 +0000
                Re: Command line arguments Fred K <fred.l.kleinschmidt@gmail.com> - 2013-01-11 14:42 -0800
                Re: Command line arguments glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-12 01:22 +0000
                Re: Command line arguments Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-01-12 01:39 +0000
                Re: Command line arguments glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-12 03:16 +0000
                Re: Command line arguments Keith Thompson <kst-u@mib.org> - 2013-01-12 09:49 -0800
                Re: Command line arguments JohnF <john@please.see.sig.for.email.com> - 2013-01-12 04:14 +0000
                Re: Command line arguments Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2013-01-13 20:19 +0200
                Re: Command line arguments JohnF <john@please.see.sig.for.email.com> - 2013-01-14 04:56 +0000
                Re: Command line arguments Ken Brody <kenbrody@spamcop.net> - 2013-01-22 15:32 -0500
              Re: Command line arguments Ken Brody <kenbrody@spamcop.net> - 2013-01-22 15:25 -0500
          Re: Command line arguments Fred K <fred.l.kleinschmidt@gmail.com> - 2013-01-10 14:49 -0800
          Re: Command line arguments glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-11 00:11 +0000
          Re: Command line arguments James Kuyper <jameskuyper@verizon.net> - 2013-01-10 21:16 -0500
          Re: Command line arguments Les Cargill <lcargill99@comcast.com> - 2013-01-11 21:25 -0600
      Re: Command line arguments James Kuyper <jameskuyper@verizon.net> - 2013-01-10 21:05 -0500
        Re: Command line arguments Shao Miller <sha0.miller@gmail.com> - 2013-01-10 21:15 -0500
          Re: Command line arguments 88888 Dihedral <dihedral88888@googlemail.com> - 2013-01-11 01:36 -0800
            Re: Command line arguments glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-11 19:33 +0000
              Re: Command line arguments Shao Miller <sha0.miller@gmail.com> - 2013-01-11 14:57 -0500
              Re: Command line arguments Robert Wessel <robertwessel2@yahoo.com> - 2013-01-11 14:26 -0600
                Re: Command line arguments glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-11 20:49 +0000
                Re: Command line arguments Robert Wessel <robertwessel2@yahoo.com> - 2013-01-11 18:15 -0600
                Re: Command line arguments Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-01-12 01:11 +0000
                Re: Command line arguments glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-12 01:38 +0000
                Re: Command line arguments Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-12 14:57 -0800
                Re: Command line arguments Shao Miller <sha0.miller@gmail.com> - 2013-01-12 18:08 -0500
                Re: Command line arguments Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-01-13 00:42 +0000
                Re: Command line arguments Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-13 12:31 -0800
                Re: Command line arguments Robert Wessel <robertwessel2@yahoo.com> - 2013-01-13 04:54 -0600
                Re: Command line arguments glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-13 12:37 +0000
                Re: Command line arguments Shao Miller <sha0.miller@gmail.com> - 2013-01-11 15:54 -0500
                Re: Command line arguments glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-11 21:16 +0000
                Re: Command line arguments Greg Martin <greg@softsprocket.com> - 2013-01-11 13:17 -0800
                Re: Command line arguments glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-11 22:48 +0000
              Re: Command line arguments gazelle@shell.xmission.com (Kenny McCormack) - 2013-01-11 22:53 +0000
              Re: Command line arguments "BartC" <bc@freeuk.com> - 2013-01-11 23:46 +0000
                Re: Command line arguments Robert Wessel <robertwessel2@yahoo.com> - 2013-01-11 18:12 -0600
                Re: Command line arguments Lew Pitcher <lpitcher@teksavvy.com> - 2013-01-11 19:59 -0500
                Re: Command line arguments Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-01-12 01:32 +0000
                Re: Command line arguments "BartC" <bc@freeuk.com> - 2013-01-12 02:47 +0000
                Re: Command line arguments Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-01-12 03:23 +0000
                Re: Command line arguments Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2013-01-11 22:28 -0700
                Re: Command line arguments Keith Thompson <kst-u@mib.org> - 2013-01-11 18:54 -0800
                Re: Command line arguments glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-12 03:42 +0000
                Re: Command line arguments James Kuyper <jameskuyper@verizon.net> - 2013-01-11 23:18 -0500
                Re: Command line arguments "BartC" <bc@freeuk.com> - 2013-01-12 12:06 +0000
                Re: Command line arguments James Kuyper <jameskuyper@verizon.net> - 2013-01-12 11:43 -0500
                Re: Command line arguments Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2013-01-12 10:27 -0700
                Re: Command line arguments Keith Thompson <kst-u@mib.org> - 2013-01-12 10:22 -0800
                Re: Command line arguments "BartC" <bc@freeuk.com> - 2013-01-12 20:26 +0000
                Re: Command line arguments glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-12 20:53 +0000
                Re: Command line arguments Geoff <geoff@invalid.invalid> - 2013-01-12 16:58 -0800
                Re: Command line arguments glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-13 01:51 +0000
                Re: Command line arguments Geoff <geoff@invalid.invalid> - 2013-01-13 00:27 -0800
                Re: Command line arguments Sjouke Burry <s@b> - 2013-01-14 06:00 +0000
                Re: Command line arguments glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-14 21:44 +0000
                Re: Command line arguments Shao Miller <sha0.miller@gmail.com> - 2013-01-12 16:10 -0500
                Re: Command line arguments "BartC" <bc@freeuk.com> - 2013-01-12 21:25 +0000
                Re: Command line arguments pacman@kosh.dhis.org (Alan Curry) - 2013-01-12 22:10 +0000
                Re: (OT keyboard input) "BartC" <bc@freeuk.com> - 2013-01-13 01:30 +0000
                Re: (OT keyboard input) Keith Thompson <kst-u@mib.org> - 2013-01-12 20:47 -0800
                Re: (OT keyboard input) pacman@kosh.dhis.org (Alan Curry) - 2013-01-13 08:46 +0000
                Re: (OT keyboard input) Robert Wessel <robertwessel2@yahoo.com> - 2013-01-13 03:56 -0600
                Re: (OT keyboard input) "BartC" <bc@freeuk.com> - 2013-01-13 12:10 +0000
                Re: (OT keyboard input) Lew Pitcher <lpitcher@teksavvy.com> - 2013-01-13 11:21 -0500
                Re: (OT keyboard input) 88888 Dihedral <dihedral88888@googlemail.com> - 2013-01-13 09:43 -0800
                Re: (OT keyboard input) "osmium" <r124c4u102@comcast.net> - 2013-01-13 12:09 -0600
                Re: (OT keyboard input) pacman@kosh.dhis.org (Alan Curry) - 2013-01-13 20:34 +0000
                Re: (OT keyboard input) "BartC" <bc@freeuk.com> - 2013-01-13 21:58 +0000
                Re: (OT keyboard input) Dr Nick <nospam-4@temporary-address.org.uk> - 2013-01-13 22:26 +0000
                Re: (OT keyboard input) Greg Martin <greg@softsprocket.com> - 2013-01-13 14:51 -0800
                Re: (OT keyboard input) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-01-13 23:47 +0000
                Re: (OT keyboard input) pacman@kosh.dhis.org (Alan Curry) - 2013-01-14 01:34 +0000
                Re: (OT keyboard input) James Kuyper <jameskuyper@verizon.net> - 2013-01-13 23:53 -0500
                Re: (OT keyboard input) Robert Wessel <robertwessel2@yahoo.com> - 2013-01-14 00:26 -0600
                Re: (OT keyboard input) James Kuyper <jameskuyper@verizon.net> - 2013-01-14 07:36 -0500
                Re: (OT keyboard input) Robert Wessel <robertwessel2@yahoo.com> - 2013-01-14 13:40 -0600
                Re: (OT keyboard input) "BartC" <bc@freeuk.com> - 2013-01-14 14:23 +0000
                Re: (OT keyboard input) "BartC" <bc@freeuk.com> - 2013-01-14 13:36 +0000
                Re: (OT keyboard input) James Kuyper <jameskuyper@verizon.net> - 2013-01-14 09:25 -0500
                Re: (OT keyboard input) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-01-14 21:09 +0000
                Re: (OT keyboard input) "BartC" <bc@freeuk.com> - 2013-01-14 22:06 +0000
                Re: (OT keyboard input) Nobody <nobody@nowhere.com> - 2013-01-15 08:16 +0000
                Re: (OT keyboard input) "BartC" <bc@freeuk.com> - 2013-01-15 11:50 +0000
                Re: (OT keyboard input) Keith Thompson <kst-u@mib.org> - 2013-01-15 07:53 -0800
                Re: (OT keyboard input) Nobody <nobody@nowhere.com> - 2013-01-15 20:26 +0000
                Re: (OT keyboard input) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-01-15 21:08 +0000
                Re: (OT keyboard input) "BartC" <bc@freeuk.com> - 2013-01-15 22:19 +0000
                Re: (OT keyboard input) James Kuyper <jameskuyper@verizon.net> - 2013-01-15 20:37 -0500
                Re: (OT keyboard input) Robert Wessel <robertwessel2@yahoo.com> - 2013-01-16 02:24 -0600
                Re: (OT keyboard input) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-01-16 04:28 +0000
                Re: (OT keyboard input) James Kuyper <jameskuyper@verizon.net> - 2013-01-16 06:44 -0500
                Re: (OT keyboard input) "BartC" <bc@freeuk.com> - 2013-01-16 13:57 +0000
                Re: (OT keyboard input) "BartC" <bc@freeuk.com> - 2013-01-16 14:32 +0000
                Re: (OT keyboard input) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-01-17 00:35 +0000
                Re: (OT keyboard input) pacman@kosh.dhis.org (Alan Curry) - 2013-01-15 23:51 +0000
                Re: (OT keyboard input) pacman@kosh.dhis.org (Alan Curry) - 2013-01-14 21:15 +0000
                Re: (OT keyboard input) "BartC" <bc@freeuk.com> - 2013-01-14 21:59 +0000
                Re: (OT keyboard input) Greg Martin <greg@softsprocket.com> - 2013-01-13 10:04 -0800
                Re: (OT keyboard input) Roberto Waltman <usenet@rwaltman.com> - 2013-01-13 20:09 -0500
      Re: Command line arguments Geoff <geoff@invalid.invalid> - 2013-01-10 23:47 -0800
    Re: Command line arguments Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2013-01-13 20:03 +0200
  Re: Command line arguments glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-10 22:30 +0000
  Re: Command line arguments Shao Miller <sha0.miller@gmail.com> - 2013-01-10 18:12 -0500
    Re: Command line arguments Shao Miller <sha0.miller@gmail.com> - 2013-01-10 18:15 -0500
    Re: Command line arguments glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-11 00:16 +0000
  Re: Command line arguments Keith Thompson <kst-u@mib.org> - 2013-01-10 15:46 -0800
  Re: Command line arguments Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2013-01-10 17:58 -0700
  Re: Command line arguments Johann Klammer <klammerj@NOSPAM.a1.net> - 2013-01-11 09:26 +0100
  Re: Command line arguments Les Cargill <lcargill99@comcast.com> - 2013-01-11 21:23 -0600
    Re: Command line arguments glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-12 03:45 +0000
    Re: Command line arguments Philip Lantz <prl@canterey.us> - 2013-01-11 20:52 -0800
      Re: Command line arguments Les Cargill <lcargill99@comcast.com> - 2013-01-11 23:21 -0600
    Re: Command line arguments Keith Thompson <kst-u@mib.org> - 2013-01-12 09:52 -0800
  Re: Command line arguments James Dow Allen <jdallen2000@yahoo.com> - 2013-01-13 01:22 -0800
    Re: Command line arguments Shao Miller <sha0.miller@gmail.com> - 2013-01-13 11:11 -0500
      Re: Command line arguments Azazel <azazel@remove.azazel.net> - 2013-01-14 09:26 -0600
        Re: Command line arguments Shao Miller <sha0.miller@gmail.com> - 2013-01-14 17:08 -0500
          Re: Command line arguments glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-14 23:13 +0000
        Re: Command line arguments 88888 Dihedral <dihedral88888@googlemail.com> - 2013-01-14 22:11 -0800

csiph-web