[comp.sys.ibm.pc] stupid COMMAND.COM

djfiander@watnot.UUCP (03/05/87)

>>For some inscrutable reason, environment substitutions (%name%) work only
>>during batch file execution. If you try them on the keyboard, it just ignores
>>you...
>
>This is a result of an idiot designing the COMMAND.COM processor.
>
>But Microsoft, in their ultimate wisdom....
>

Something that I discovered after getting the MKS toolkit (before they
had KSH ready for release) was that it is physically impossible to
pass certain characters to a program on the commandline, specifically
" ' * ? | etc.

Once again Microsoft could not forsee _any_ possible reason that a program
would want to see one of these characters.

Obviously this cut down on the usefulness of things like sed, egrep,
find, and so on.

-- 
"I don't want to achieve immortality through my work.
I want to achieve immortality through not dying"
	- Woody Allen

UUCP  : {allegra,ihnp4,decvax,utzoo,clyde}!watmath!watnot!djfiander
CSNET : djfiander%watnot@waterloo.CSNET

dlnash@ut-ngp.UUCP (03/08/87)

In article <12559@watnot.UUCP>, djfiander@watnot.UUCP writes:
> 
> Something that I discovered after getting the MKS toolkit (before they
> had KSH ready for release) was that it is physically impossible to
> pass certain characters to a program on the commandline, specifically
> " ' * ? | etc.
  ^ ^ ^ ^ ^
> 

I wrote a quicky C program which contained just printf("%s\n", argv[1]);
I could pass all of those characters highlighted above and also < and >.
The only thing I had to do is enclose | < and > in double quotes.  I
also wrote a batch file which was just echo %1.  I got the same results.
You can pass any character on the command line, if you put it in double
quotes.  However, the quotes are not stripped.  This is for PC-DOS 3.1
on an IBM PC XT.

				Don Nash

UUCP:    ...!{ihnp4, allegra, seismo!ut-sally}!ut-ngp!dlnash
ARPA:    dlnash@ngp.UTEXAS.EDU
BITNET:	 CCEU001@UTADNX, DLNASH@UTADNX
TEXNET:  UTADNX::CCEU001, UTADNX::DLNASH

UUU       UUU
 U         U                The University of Texas at Austin
 U     TTTTUTTTTTTTTT              Computation Center
 U     T   U TT     T
  U       U  TT            "The world is basically non-linear."
   UUUUUUU   TT
             TT 
            TTTT

djfiander@watnot.UUCP (03/08/87)

>> Something that I discovered after getting the MKS toolkit (before they
>> had KSH ready for release) was that it is physically impossible to
>> pass certain characters to a program on the commandline, specifically
>> " ' * ? | etc.
>  ^ ^ ^ ^ ^
>I wrote a quicky C program which contained just printf("%s\n", argv[1]);
>I could pass all of those characters highlighted above and also < and >.
>The only thing I had to do is enclose | < and > in double quotes.  ...
> This is for PC-DOS 3.1 on an IBM PC XT.
>
>				Don Nash

Oops, * and ? are passed inside double quotes (sorry), but under DOS
3.0 the others are still not passed.  I know this because I tried to 
use '|' in an egrep pattern.  DOS passed the first part of the pattern to
egrep and tried to execute the second part.

-- 
"I don't want to achieve immortality through my work.
I want to achieve immortality through not dying"
	- Woody Allen

UUCP  : {allegra,ihnp4,decvax,utzoo,clyde}!watmath!watnot!djfiander
CSNET : djfiander%watnot@waterloo.CSNET

dalegass@dalcs.UUCP (03/12/87)

In article <12572@watnot.UUCP>, djfiander@watnot.UUCP writes:
> >>                                     it is physically impossible to
> >> pass certain characters to a program on the commandline, specifically
> >> " ' * ? | etc.
> >  ^ ^ ^ ^ ^
> >I wrote a quicky C program which contained just printf("%s\n", argv[1]);
> >I could pass all of those characters highlighted above and also < and >.
> >The only thing I had to do is enclose | < and > in double quotes.  ...
> > This is for PC-DOS 3.1 on an IBM PC XT.
> 
> Oops, * and ? are passed inside double quotes (sorry), but under DOS
> 3.0 the others are still not passed.  I know this because I tried to 
> use '|' in an egrep pattern.  DOS passed the first part of the pattern to
> egrep and tried to execute the second part.
> 

I'm pretty sure that DOS does not do all of the redirection.  Of course it
handles redirection for it's own built-in commands (COPY,ECHO,etc.) but
as far as executables go, they must do the work themselves.

Most (if not all) C compilers will automatically handle this for you in
their startup routine (which allocates memory, initializes channels, and so
on).  I've seen the source code for Aztec C, and redirection is taken care
of from the program which is executed, and is not a trapping at the DOS
level.

This means that different C compilers might parse the " character a bit
differently; hence the discrepancy between results.  The C compiler which
Microsoft used for their transient (.com .exe) commands could very likely
perform a bit differently from a program compiled by another version of C.

When DOS gives control to a .com or .exe file, it simply passes the whole
command line to it, and let's it do what it wishes with the info.
I think, however, that piping '|' *is* intercepted at the DOS level,
whereas the '>' and '<' redirections are not.

-dalegass@dalcs

rjchen@phoenix.UUCP (03/13/87)

In article <2438@dalcs.UUCP> dalegass@dalcs.UUCP writes:
>> [general discussion on inability to pass various marks of punctuation
>>  on the command line since they are DOS metacharacters.]
>
> ...I've seen the source code for Aztec C, and redirection is taken care
>of from the program which is executed, and is not a trapping at the DOS
>level. ...
>
>When DOS gives control to a .com or .exe file, it simply passes the whole
>command line to it, and let's it do what it wishes with the info.
>I think, however, that piping '|' *is* intercepted at the DOS level,
>whereas the '>' and '<' redirections are not.
>
>-dalegass@dalcs

I scribbled up a quick assembly language program which does an UNWS,
and merely call it with UNWS <infile >outfile.  My program just reads
everything off stdin and dumps it to stdout.  So DOS >does< catch the
">" and "<" and takes them out.

I don't know why Aztec C does all that redirection handling, but MIX C
(don't laugh) also does the same thing in its startup routine.  They
do it presumably because MIX C was originally a CP/M compiler, and CP/M
does not handle redirection.  Perhaps they were too lazy to remove it
from their MSDOS version, or maybe they know something we don't.

-- 
-- Raymond Chen, BITNET: (preferably) 6101695@pucc, rjchen@pucc
                 ARPA: rjchen@phoenix.PRINCETON.EDU
                 UUCP: {allegra}!princeton!phoenix!rjchen

nortond@well.UUCP (03/14/87)

In article <134@phoenix.PRINCETON.EDU>, rjchen@phoenix.PRINCETON.EDU (Raymond Juimong Chen) writes:
> 
> I don't know why Aztec C does all that redirection handling, but MIX C
> (don't laugh) also does the same thing in its startup routine. 

Only the later version of DOS supported Standard I/O redirection (I forget
when they started doing it).  The startup code does the redirection only if
DOS did not do the redirection for the program.  Since, as you mentioned,
DOS strips the ">" and "<", the startup code doesn't do anything anyway
on the later versions of DOS.

-- 
Daniel A. Norton    ...!lll-lcc!{lll-crg,ptsfa}!well!nortond

brandon@tdi2.UUCP (03/18/87)

Quoted from <134@phoenix.PRINCETON.EDU> ["Re: stupid COMMAND.COM  (WAS:  DOS enviroment size)"], by rjchen@phoenix.PRINCETON.EDU (Raymond Juimong Chen)...
+---------------
| In article <2438@dalcs.UUCP> dalegass@dalcs.UUCP writes:
| > ...I've seen the source code for Aztec C, and redirection is taken care
| >of from the program which is executed, and is not a trapping at the DOS
| >level. ...
| >
| >When DOS gives control to a .com or .exe file, it simply passes the whole
| >command line to it, and let's it do what it wishes with the info.
| >I think, however, that piping '|' *is* intercepted at the DOS level,
| >whereas the '>' and '<' redirections are not.
| 
| I scribbled up a quick assembly language program which does an UNWS,
| and merely call it with UNWS <infile >outfile.  My program just reads
| everything off stdin and dumps it to stdout.  So DOS >does< catch the
| ">" and "<" and takes them out.
+---------------

Approximate quote from my DOS manual (ITT-DOS 2.11):

``COMMAND.COM strips redirection information from the command line before
passing it to the program.''

Presumably, if the redirection information isn't in the program's image of the
command line, then COMMAND.COM is doing the redirection (otherwise, *nothing*
is!).

++Brandon
-- 
``for is he not of the Children of Luthien?  Never shall that line fail, though
the years may lengthen beyond count.''  --J. R. R. Tolkien

Brandon S. Allbery	           UUCP: cbatt!cwruecmp!ncoast!tdi2!brandon
Tridelta Industries, Inc.         CSNET: ncoast!allbery@Case
7350 Corporate Blvd.	       INTERNET: ncoast!allbery%Case.CSNET@relay.CS.NET
Mentor, Ohio 44060		  PHONE: +1 216 255 1080 (home) +1 216 974 9210