950
|
1 |
.. -*- coding: utf-8; -*-
|
|
2 |
|
|
3 |
====================
|
|
4 |
CMD Windows shell.
|
|
5 |
====================
|
|
6 |
.. contents::
|
|
7 |
|
|
8 |
Quoting.
|
|
9 |
========
|
|
10 |
|
|
11 |
* Arguments are delimited by white space, which is either a space or a tab.
|
|
12 |
* A string surrounded by double quotation marks is interpreted as a single
|
|
13 |
argument.
|
|
14 |
* A double quotation mark preceded by a backslash, \", is interpreted as a
|
|
15 |
literal double quotation mark.
|
|
16 |
* Backslashes are interpreted literally, unless they immediately precede a
|
|
17 |
double quotation mark.
|
|
18 |
* If an even number of backslashes is followed by a double quotation mark,
|
|
19 |
then one backslash (\) is placed in the argv array for every pair of
|
|
20 |
backslashes (\\), and the double quotation mark (") is interpreted as a
|
|
21 |
string delimiter.
|
|
22 |
* If an odd number of backslashes is followed by a double quotation mark,
|
|
23 |
then one backslash (\) is placed in the argv array for every pair of
|
|
24 |
backslashes (\\) and the double quotation mark is interpreted as an escape
|
|
25 |
sequence by the remaining backslash, causing a literal double quotation
|
|
26 |
mark (") to be placed in argv.
|
|
27 |
* In double quote mark need surround such chars::
|
|
28 |
|
|
29 |
& < > [ ] { } ^ = ; ! ' + , ` ~ %
|
|
30 |
|
|
31 |
Also all this char can be escaped by ^ char.
|
|
32 |
* Long line can be truncated by ^ char, in this case trailing white spaces
|
|
33 |
not allowed.
|
|
34 |
* To quote percent sign % before alpha char in batch file double it
|
|
35 |
occurrences or plase in quotes::
|
|
36 |
|
|
37 |
prog '%'HOME'%' "%"HOME"%" %%HOME%
|
|
38 |
|
|
39 |
http://msdn.microsoft.com/en-us/library/ms880421.aspx
|
|
40 |
Parsing C Command-Line Arguments
|
|
41 |
|
|
42 |
Variables.
|
|
43 |
==========
|
|
44 |
|
|
45 |
Variable name start with letter and underscore, next chars can be letter,
|
|
46 |
number and underscore. Variable name is case insensitive.
|
|
47 |
|
|
48 |
List of variables.
|
|
49 |
------------------
|
|
50 |
::
|
|
51 |
|
|
52 |
cmd> set
|
|
53 |
...
|
|
54 |
VAR=VALUE
|
|
55 |
|
|
56 |
Getting.
|
|
57 |
--------
|
|
58 |
|
|
59 |
Write %VAR% in place where you want insert variable VAr value.
|
|
60 |
|
|
61 |
Setting.
|
|
62 |
--------
|
|
63 |
::
|
|
64 |
|
|
65 |
cmd> set /p VAR=VALUE
|
|
66 |
|
|
67 |
Deleting.
|
|
68 |
---------
|
|
69 |
::
|
|
70 |
|
|
71 |
cmd> set VAR=
|
|
72 |
|
|
73 |
Input from user.
|
|
74 |
----------------
|
|
75 |
::
|
|
76 |
|
|
77 |
cmd> set /p VAR=PROMPT
|
|
78 |
|
|
79 |
VAR is variable name, PROMPT is displayed prompt.
|
|
80 |
|
|
81 |
Input from file.
|
|
82 |
----------------
|
|
83 |
|
|
84 |
cmd> set /p VAR=<FILE
|
|
85 |
|
|
86 |
VAR is variable name, FILE is file name. Sfter executing VAR contain first
|
|
87 |
line from FILE.
|
|
88 |
|
|
89 |
CMD tricks.
|
|
90 |
===========
|
|
91 |
::
|
|
92 |
|
|
93 |
$ set /p TOOLOUTPUT= < temp.txt
|
|
94 |
|
|
95 |
$ for /f "tokens=*" %%i in ('%~dp0sometool.exe') do set TOOLOUTPUT=%%i
|
|
96 |
|
|
97 |
$ for /f "tokens=1 delims=" %%s in (users.txt) do (echo %%S & command "%%S") >> outputfile.txt
|
|
98 |
|
1075
|
99 |
Resize cmd window.
|
|
100 |
==================
|
|
101 |
::
|
|
102 |
|
|
103 |
cmd# mode CON: COLS=120 LINES=40
|
|
104 |
|
950
|
105 |
Limits.
|
|
106 |
=======
|
|
107 |
|
|
108 |
Variable value and one line command string after expansion can not exceed 8191
|
|
109 |
characters for Windows XP and later and 2047 for Windows NT, Windows 2000.
|
|
110 |
|
|
111 |
http://support.microsoft.com/default.aspx?scid=kb;en-us;830473
|
|
112 |
Command prompt (Cmd. exe) command-line string limitation
|
|
113 |
|
|
114 |
How run cmd on 64-bit OS.
|
|
115 |
=========================
|
|
116 |
|
|
117 |
From 64-bit process::
|
|
118 |
|
|
119 |
%windir%\System32\cmd.exe (for 64-bit)
|
|
120 |
%windir%\SysWOW64\cmd.exe (for 32-bit)
|
|
121 |
|
|
122 |
From 32-bit process::
|
|
123 |
|
|
124 |
%windir%\System32\cmd.exe (for 32-bit)
|
|
125 |
%windir%\Sysnative\cmd.exe (for 64-bit)
|
|
126 |
|
|
127 |
http://msdn.microsoft.com/en-us/library/aa384187%28VS.85%29.aspx
|
|
128 |
File System Redirector
|
|
129 |
|