Dos command lines and -c "text" 
Author Message
 Dos command lines and -c "text"

MS-DOS COMMAND LINE PARAMATER SUBSTITUTION
AND ITS EFFECT ON python -C COMMAND INPUT


1997 Dec 8

In the course of writing an article on self-reproducing Python programs,
I discovered that in later versions of MS-DOS, command lines, viewed as
one string, are processed much like Python key-value format strings.  
The similarities are that quote characters within the line (string) have
no special meaning and '%%' is replaced by '%'.  The differences are
that key replacement is syntactically indicated by '%key%' instead of
'%(key)s', the replacement dictionary is the environment rather than one
specified, and missing keys default to '' as the replacement instead of
raising an execption.  The echo command illustrates the rules:

echo input      echo response
%%              %
"%%"          "%"
%not-key%       ECHO is on [command.com just sees 'echo']
1%not-key%2     12
%TMP%           C:\WINDOWS\TEMP
"%TMP%"               "C:\WINDOWS\TEMP"
a%b             a%b
'%s'% 1         ' 1
'%s%%'%1        1

Although my Microsoft MS-DOS User's Reference (4.0) only describes this
in a hard-to-find section entitled 'How to Use Named Parameters in a
Batch File', the substitution also applies to interactive command lines,
at least in a Win95 DOS window.  As the last two examples show, this
will usually disable python -c "command" whenever 'command' contains a
format expression.  As shown by the next two examples, the solution is
to double the %s.

'%%s'%%1        '%s'%1
'%%s%%%%'%%1    '%s%%'%1



Sun, 28 May 2000 03:00:00 GMT  
 Dos command lines and -c "text"


 >In the course of writing an article on self-reproducing Python programs,
 >I discovered that in later versions of MS-DOS, command lines, viewed as
 >one string, are processed much like Python key-value format strings.  
 >The similarities are that quote characters within the line (string) have
 >no special meaning and '%%' is replaced by '%'.  The differences are
 >that key replacement is syntactically indicated by '%key%' instead of
 >'%(key)s', the replacement dictionary is the environment rather than one
 >specified, and missing keys default to '' as the replacement instead of
 >raising an execption.  The echo command illustrates the rules:
 >
 >echo input      echo response
 >%%              %
 >"%%"            "%"
 >%not-key%       ECHO is on [command.com just sees 'echo']
 >1%not-key%2     12
 >%TMP%           C:\WINDOWS\TEMP
 >"%TMP%"         "C:\WINDOWS\TEMP"

under NT 4, I get:
C:\>echo %%
%%

C:\>echo %not-key%
%not-key%

C:\>echo 1%not-key%2
1%not-key%2

C:\>echo %TMP%
C:\TEMP

C:\>echo %
%

C:\>echo '%TMP%'
'C:\TEMP'

--
- Gordon McMillan
McMillan Enterprises, Inc. | http://www.mcmillan-inc.com/



Mon, 29 May 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Problem with "-r" command line argument

2. "DOS" commands in REXX under NT

3. REXX: LINES() and "complete lines"

4. string.join(["Tk 4.2p2", "Python 1.4", "Win32", "free"], "for")

5. How to get DOS command line text

6. BEGIN{want[]={"s1o", "s2o", "s2q", "s3q"}

7. Avoiding "/double-quotes in the command line

8. Parsing ""D""?

9. "Fifth", "Forth", zai nar?

10. Ruby "finalize", "__del__"

11. beginners "let"/"random" question

12. ANNOUNCE: new "plus"- and "dash"-patches available for Tcl7.5a2/Tk4.1a2

 

 
Powered by phpBB® Forum Software