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