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