Escaped Characters and Variables

Apr 28, 2017
1
0
I'm using TCC 19.10.54 x64 in Windows 7 Pro 64bit to run a batch file that accepts two arguments from the command line. The second argument contains escaped characters. In the batch, I'm assigning the second argument to a variable. I'm having problems with the variable displaying the correct output. The variable should display the same output as the command line argument2, however the variable displays different output. Below is the batch file code and the actual and expected output. Also, I tried this with TCC 21.00.20 x64 and get the same output. Is this the incorrect way to do this, a bug, or this cannot be done this way?

Code:
@echo off

rem Print the command line argument1 value.
echo cmdline arg1 value is: %1

rem Print the command line argument2 value.
echo cmdline arg2 value is: %2

rem Assign the command line argument2 value to a variable.
set arg2=%2

rem Print the variable containing the command line argument2 value.
echo variable arg2 value is: %arg2

quit

Actual Output
--------------
[C:\Users\testuser\AppData\Local\Temp]bf.bat x @^%^%$#
cmdline arg1 value is: x
cmdline arg2 value is: @%$#
variable arg2 value is: @x @%$##

Excepted Output
----------------
[C:\Users\testuser\AppData\Local\Temp]bf.bat x @^%^%$#
cmdline arg1 value is: x
cmdline arg2 value is: @%$#
variable arg2 value is: @%$#

Thanks.
 
May 20, 2008
11,404
99
Syracuse, NY, USA
The problem is that when you echo %arg2, the %$ is interpreted at the whole set of args to the batch file (see "Batch File Parameters"). I would have expected "SETDOS /X-2" to prevent that but it doesn't.
 
May 20, 2008
11,404
99
Syracuse, NY, USA
As I said before. %$ is a problem (meaning all the batfile's arguments). I was using the wrong SETDOS syntax. SETDOS /x-4 works.
Code:
v:\> t.btm x @^%^%$#
cmdline arg1 value is: x
cmdline arg2 value is: @%$#
arg2 is @%$#
variable arg2 value is: @%$#

v:\> type t.btm

rem Print the command line argument1 value.
echo cmdline arg1 value is: %1

rem Print the command line argument2 value.
echo cmdline arg2 value is: %2

rem Assign the command line argument2 value to a variable.
set arg2=%2

setdos /x-4
rem Print the variable containing the command line argument2 value.
echo variable arg2 value is: %[arg2]
setdos /x+4


v:\> t.btm x @^%^%$#
cmdline arg1 value is: x
cmdline arg2 value is: @%$#
variable arg2 value is: @%$#
 
Similar threads
Thread starter Title Forum Replies Date
JohnQSmith WAD DO and escaped redirect characters Support 6
vefatica TPIPE: unbalanced escaped quotes in a regex? Support 5
S WAD Escaped "r" dropped Support 13
R WAD Unusable state when using Chinese characters Support 3
C TEE command appending null characters to output Support 6
D Regexes and escape characters Support 5
vefatica Quoting file names with special characters? Support 7
vefatica How to? Add real <ESC> characters with TPIPE Support 2
C Erase all characters left or right from cursor location Support 2
Joe Caverly Unicode, Codepage 437, and line characters Support 3
gschizas Fixed Using codepage 65001 (UTF-8) breaks non-ASCII characters Support 8
vefatica Display of special characters in aliases. Support 25
J Python: TCC command line parsing removes '=' equal sign characters Support 4
C filemasks over 172 characters fail Support 5
redwdc TCC.exe opens to 11 characters x 3 rows Support 1
G Selection characters with mouse double-click Support 3
R Function #IDOW returns only 2 characters Support 10
krischik WAD Tee printing Chinese characters Support 7
Alexander How to? how can I use Cyrillic characters in the Echo command? Support 8
jadaml Echo unicode characters from UTF-8 Batch files? Support 1
V Fixed CD ~ has trash characters in it Support 5
S International characters - TYPE vs %@LINE function Support 5
Jay Sage Getting Quote Characters into a Toolbar Tab Support 12
vefatica Fixed Escaping special characters Support 1
M Problem with Extended Search and non-ASCII characters in directories names Support 3
A How to? PhraseExpress autotext/autocompletion printing unexpected characters Support 4
thedave WAD Unable to type various characters using Windows 8's onscreen keyboard Support 7
W TCMD 16: double characters Support 11
MickeyF how to work with env var with special characters in the name Support 5
vefatica Fixed TPIPE doesn't /SPLIT at characters Support 0
A Escape characters on right side of pipe Support 0
J How to? 'tab' characters in the console and clipboard 'copy' Support 1
M How to? Determine a whether vars beginning with certain characters exist... Support 5
M Another simple question re. Take Command/TCC window witdth in characters... Support 16
U Keystack mangles 'special' characters Support 6
J dir failure with some unicode characters Support 6
vefatica Random access to the characters in a string? Support 4
nikbackm @select function and TAB characters Support 1
M Overriding meanings of some characters... Support 7
T How do you echo lines with special characters to file? Support 4
Emilio III Control characters pass through? Support 6
S Strange REN problem - non-English characters Support 3
nikbackm Output of non-ascii characters via pipe Support 1
K Processing strings with % characters? Support 2
W Bugs in dealing with Chinese characters? Support 0
Peter Murschall v27.00.16/17: ENDLOCAL with exporting variables wipes out the complete Environment Support 2
S How to? best way to compose data for command to use out of presets/variables Support 1
Joe Caverly START Dialog usage of %_ variables Support 0
Joe Caverly Modified Variables in CMDebug/BDebugger Support 1
T How to? Show the values of batch variables on the TCC screen Support 21

Similar threads