title: How to receive even the strangest command line parameters?
body: <p>as discussed in an other thread <a href="https://stackoverflow.com/questions/3813370/how-to-avoid-cmd-exe-interpreting-shell-special-characters-like">How to avoid cmd.exe interpreting shell special characters like &lt; > ^</a>
  it is not easy to get all parameters from the command line.</p>
  
  <p>A simple </p>
  
  <pre><code>set var=%1
  set "var=%~1"
  </code></pre>
  
  <p>are not enough, if you have a request like</p>
  
  <pre><code>myBatch.bat abc"&amp;"^&amp;def
  </code></pre>
  
  <p>I have one solution, but it needs a temporary file, and it is also not bullet proof.</p>
  
  <pre><code>@echo off
  setlocal DisableDelayedExpansion
  set "prompt=X"
  (
      @echo on
      for %%a 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>It fails with something like <strong>myBatch.bat %a</strong>, it display <strong>4</strong> not the <strong>%a</strong></p>
  
  <p>in this situation a simple <strong>echo %1</strong> would work.<br>
  It's obviously the for-loop but I don't know how to change this.<br>
  Perhaps there exists another simple solution.</p>
  
  <p>I don't need this to solve an actual problem, but I like solutions that are bullet proof in each situation, not only in the most cases.</p>