From a DOS batch script I want to pass a command/string to a program (here:mysql.exe)
This string parameter contains a %....% token which should NOT be replaced by a DOS batch variable but passed exactly as written to mysql.exe
From cmdline it works fine.
How can I prevent replacement? The percentage sign MUST be passed to mysql.
The following does NOT work:
mysql.exe -u myuser -pmypasswd -e "show variables like '%version%';"
mysql.exe -u myuser -pmypasswd -e "show variables like '\%version\%';"
So how could that work?
Thank you
Peter
How to mask %....% in string "....."?
Moderator: DosItHelp
Re: How to mask %....% in string "....."?
'
Hi pstein,
unfortunately CMD does not support regular expressions, try:
Hi pstein,
unfortunately CMD does not support regular expressions, try:
Code: Select all
mysql.exe -u myuser -pmypasswd -e "show variables like '%%version%%';"
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: How to mask %....% in string "....."?
There are a few characters that need special handling in batch.
The caret character ^ is batch's escape character, so you would write & like ^&.
It's preferable to write characters within quotation marks (special character processing is disabled within quotation marks, so no problematic carets are needed).
The only two exceptions to that are ! (when delayedexpansion is enabled, needs any number of preceding carets) and %, like your case.
% is easy though. Simply double the character up. %% = %. This is why for loops require %% for its tokens within batch scripts, and not when directly on the command line.
The caret character ^ is batch's escape character, so you would write & like ^&.
It's preferable to write characters within quotation marks (special character processing is disabled within quotation marks, so no problematic carets are needed).
The only two exceptions to that are ! (when delayedexpansion is enabled, needs any number of preceding carets) and %, like your case.
% is easy though. Simply double the character up. %% = %. This is why for loops require %% for its tokens within batch scripts, and not when directly on the command line.