david@wubios.wustl.edu (David J. Camp) (02/16/90)
I was using Microsoft C, and had a program that used command line arguments and read the standard input. When I specified: command arg1 arg2 ... argn-1 < filename The argc variable reflected the presence of the filename. i.e. it had the value n+1. When I specified: type filename | command arg1 arg2 ... argn-1 it was not indicated, i.e. it had the value n. I think this must be a compiler bug. -David- Bitnet: david@wubios.wustl ^ Mr. David J. Camp Internet: david%wubios@wugate.wustl.edu < * > Box 8067, Biostatistics uucp: uunet!wugate!wubios!david v 660 South Euclid Washington University (314) 36-23635 Saint Louis, MO 63110
Ralf.Brown@B.GP.CS.CMU.EDU (02/16/90)
In article <1022@wubios.wustl.edu>, david@wubios.wustl.edu (David J. Camp) wrote: }I was using Microsoft C, and had a program that used command line }arguments and read the standard input. When I specified: } } command arg1 arg2 ... argn-1 < filename } }The argc variable reflected the presence of the filename. }i.e. it had the value n+1. }When I specified: } } type filename | command arg1 arg2 ... argn-1 } }it was not indicated, i.e. it had the value n. I think this must }be a compiler bug. -David- DOS doesn't strip any whitespace preceding the redirection characters, so I would guess that the startup code is seeing the blank following argn-1 and assuming that there is another argument, which turns out to be empty. Try adding a blank to the send of your second example; it should set argc to n+1. -- UUCP: {ucbvax,harvard}!cs.cmu.edu!ralf -=- 412-268-3053 (school) -=- FAX: ask ARPA: ralf@cs.cmu.edu BIT: ralf%cs.cmu.edu@CMUCCVMA FIDO: Ralf Brown 1:129/46 "How to Prove It" by Dana Angluin Disclaimer? I claimed something? 14. proof by importance: A large body of useful consequences all follow from the proposition in question.
cs00jmc@unccvax.UUCP (John Covington WN4BBJ) (02/17/90)
In article <1022@wubios.wustl.edu> david@wubios.UUCP (David J. Camp) writes: >I was using Microsoft C, and had a program that used command line >arguments and read the standard input. When I specified: > > command arg1 arg2 ... argn-1 < filename > >The argc variable reflected the presence of the filename. >i.e. it had the value n+1. >When I specified: > > type filename | command arg1 arg2 ... argn-1 > >it was not indicated, i.e. it had the value n. I think this must >be a compiler bug. -David- > Actually, argc does not indicate the presence of filename at all. In C programs argv[0] is supposed to point to the name of the program currently being run (in this case command). Thus argc will always be at least 1. If arg1 is present then argc = 2, etc. Filename is never passed to the program because DOS opens the file and attaches it to stdin. --John -- John Covington WN4BBJ E-mail: cs00jmc@unccvax.uncc.edu P.O. Box 217122 MCI Mail: JCOVINGTON 342-6957 Charlotte, NC 28221-7122 Packet Radio: WN4BBJ @ W4BFB (704) 537-7653 Voice Mail: (704) 535-5404 mbx 3407 "Hugo Was Here" 9/22/89 "Give it back, Eric, it's not yours" (the ICOM)