Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One way is to work with delayed expansion inside of the batch, because then the special characters lose there "special" meanings.</p> <p>The only problem is to get the parameters into a variable.</p> <p>Something like this could help</p> <pre><code>@echo off setlocal DisableDelayedExpansion rem ** At this point the delayedExpansion should be disabled rem ** otherwise an exclamation mark in %1 can remove carets set "param1=%~1" setlocal EnableDelayedExpansion rem ** Now you can use the param1, independent of the content, even with carets or quotes rem ** but be careful with call's, because they start a second round of expansion echo !param1! set "tmp=!param1:~1,4!" </code></pre> <p>Now the parameters can be surround by quotation marks, so there the carets aren't neccessary anymore. Example launcher.bat "abc>def&amp;geh%ijk|lmn^opq!"</p> <p>The only remaining problematic special character seems to be the quotation mark.</p> <p><strong>[Edit/Improve] I create another way to retrieve a parameter, I assume it can accept any string also your second example.</strong><br> Even really hard strings like</p> <p>launcher "^<br> launcher ten^>one<br> launcher "&amp;"^&amp; </p> <pre><code>@echo off setlocal DisableDelayedExpansion set "prompt=X" for %%a in (1 ) do ( @echo on for %%b in (4) do ( rem #%1# ) ) &gt; XY.txt @echo off for /F "delims=" %%a in (xy.txt) DO ( set "param=%%a" ) setlocal EnableDelayedExpansion set param=!param:~7,-4! echo param='!param!' </code></pre> <p>How it works?<br> The only way I have found to expand %1 without expanding the special characters like " or ^ is in a REM statement (For REM that's not completly true, but that is an other story) Ok, the only problem is that a REM is a remark and has no effect :-) </p> <p>But if you use <strong>echo on</strong> also rem lines are echoed before they are executed (execute for rem is a nice word).<br> The next problem is that it is displayed and you can not redirect this <strong>debug output</strong> with the normal > debug.txt. This is also true if you use a for-loop. </p> <p>Ok, you can redirect the <strong>echo on</strong> output with a call like </p> <pre><code>echo on call :myFunc &gt; debug.txt </code></pre> <p>But if you call a function you can't access the %1 of the batch file anymore. </p> <p>But with a double for-loop, it is possible to activate the redirection for the debug output and it's still possible to access %1.<br> I change the prompt to "X", so I know it is always only one character long.</p> <p>The only thing left is to explain why I append a # to %1.<br> That's because, some special characters are recognized in some situations even in a REM line, obviously ;-) </p> <pre><code>rem This is a remark^ rem This_is_a_multiline^ rem "This is also a multiline"^ </code></pre> <p>So the # suppress a possible multiline situation.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload