|
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 |
|
99 Limits. |
|
100 ======= |
|
101 |
|
102 Variable value and one line command string after expansion can not exceed 8191 |
|
103 characters for Windows XP and later and 2047 for Windows NT, Windows 2000. |
|
104 |
|
105 http://support.microsoft.com/default.aspx?scid=kb;en-us;830473 |
|
106 Command prompt (Cmd. exe) command-line string limitation |
|
107 |
|
108 How run cmd on 64-bit OS. |
|
109 ========================= |
|
110 |
|
111 From 64-bit process:: |
|
112 |
|
113 %windir%\System32\cmd.exe (for 64-bit) |
|
114 %windir%\SysWOW64\cmd.exe (for 32-bit) |
|
115 |
|
116 From 32-bit process:: |
|
117 |
|
118 %windir%\System32\cmd.exe (for 32-bit) |
|
119 %windir%\Sysnative\cmd.exe (for 64-bit) |
|
120 |
|
121 http://msdn.microsoft.com/en-us/library/aa384187%28VS.85%29.aspx |
|
122 File System Redirector |
|
123 |