99
|
1 |
-*- outline -*-
|
|
2 |
|
355
|
3 |
* Quoting.
|
|
4 |
|
|
5 |
* Arguments are delimited by white space, which is either a space or a tab.
|
|
6 |
* A string surrounded by double quotation marks is interpreted as a single
|
|
7 |
argument.
|
|
8 |
* A double quotation mark preceded by a backslash, \", is interpreted as a
|
|
9 |
literal double quotation mark.
|
|
10 |
* Backslashes are interpreted literally, unless they immediately precede a
|
|
11 |
double quotation mark.
|
|
12 |
* If an even number of backslashes is followed by a double quotation mark,
|
|
13 |
then one backslash (\) is placed in the argv array for every pair of
|
|
14 |
backslashes (\\), and the double quotation mark (") is interpreted as a
|
|
15 |
string delimiter.
|
|
16 |
* If an odd number of backslashes is followed by a double quotation mark,
|
|
17 |
then one backslash (\) is placed in the argv array for every pair of
|
|
18 |
backslashes (\\) and the double quotation mark is interpreted as an escape
|
|
19 |
sequence by the remaining backslash, causing a literal double quotation
|
|
20 |
mark (") to be placed in argv.
|
|
21 |
* In double quote mark need surround such chars:
|
|
22 |
& < > [ ] { } ^ = ; ! ' + , ` ~
|
|
23 |
|
|
24 |
http://msdn.microsoft.com/en-us/library/ms880421.aspx
|
|
25 |
Parsing C Command-Line Arguments
|
|
26 |
|
215
|
27 |
* Variables.
|
|
28 |
|
|
29 |
Variable name start with letter and underscore, next chars can be letter,
|
|
30 |
number and underscore. Variable name is case insensitive.
|
|
31 |
|
|
32 |
** List of variables.
|
|
33 |
|
|
34 |
cmd> set
|
|
35 |
...
|
|
36 |
VAR=VALUE
|
|
37 |
|
|
38 |
** Getting.
|
|
39 |
|
|
40 |
Write %VAR% in place where you want insert variable VAr value.
|
|
41 |
|
|
42 |
** Setting.
|
|
43 |
|
|
44 |
cmd> set /p VAR=VALUE
|
|
45 |
|
|
46 |
VAR is variable name, VALUE is value.
|
|
47 |
|
|
48 |
** Deleting.
|
|
49 |
|
|
50 |
cmd> set VAR=
|
|
51 |
|
|
52 |
VAR is variable name.
|
|
53 |
|
216
|
54 |
** Input from user.
|
215
|
55 |
|
|
56 |
cmd> set /p VAR=PROMPT
|
|
57 |
|
|
58 |
VAR is variable name, PROMPT is displayed prompt.
|
|
59 |
|
216
|
60 |
** Input from file.
|
215
|
61 |
|
|
62 |
cmd> set /p VAR=<FILE
|
|
63 |
|
|
64 |
VAR is variable name, FILE is file name. Sfter executing VAR contain first
|
|
65 |
line from FILE.
|
|
66 |
|
99
|
67 |
* CMD tricks.
|
|
68 |
|
|
69 |
$ set /p TOOLOUTPUT= < temp.txt
|
|
70 |
|
|
71 |
$ for /f "tokens=*" %%i in ('%~dp0sometool.exe') do set TOOLOUTPUT=%%i
|
|
72 |
|
|
73 |
$ for /f "tokens=1 delims=" %%s in (users.txt) do (echo %%S & command "%%S") >> outputfile.txt
|
350
|
74 |
|
|
75 |
* Limits.
|
|
76 |
|
|
77 |
Variable value and one line command string after expansion can not exceed 8191
|
|
78 |
characters for Windows XP and later and 2047 for Windows NT, Windows 2000.
|
|
79 |
|
|
80 |
http://support.microsoft.com/default.aspx?scid=kb;en-us;830473
|
|
81 |
Command prompt (Cmd. exe) command-line string limitation
|