title: NSIS Runtime CMD with spaces in path and parameter
body: <p>I have a Windows .bat script which needs to be run from a NSIS installer at runtime.</p>
  
  <p>The script is invoked as follows:</p>
  
  <pre><code>   ; Debug Messages to check values set correctly
     MessageBox MB_OK "Script ${INSTDIR}\script\settingsLocation.bat"
     MessageBox MB_OK "INSTDIR $INSTDIR "
     MessageBox MB_OK "SettingsDirType $SettingsDirType"
     MessageBox MB_OK "SettingsDirName $SettingsDirName"
     MessageBox MB_OK "Calling script ${INSTDIR}\script\settingsLocation.bat $INSTDIR $SettingsDirType $SettingsDirName"
  
     nsExec::ExecToStack 'CMD.exe /C ""${INSTDIR}\script\settingsLocation.bat"" ""${INSTDIR}"" $SettingsDirType $SettingsDirName'
  
     ; Check result status and output
     Pop $0
     MessageBox mb_ok "CMDout 0=$0"
     Pop $0
     MessageBox mb_ok "CMD Out 1=$0"
  </code></pre>
  
  <p>Using the above, the variable <code>$INSTDIR</code> is not expanded, so not surprising the command fails to find the script.</p>
  
  <p><code>$INSDIR</code> is <code>"C:\Program Files (x86)\Prog Name"</code> (three spaces).</p>
  
  <p>But I use the following (replace the <code>""</code> with <code>"</code>):</p>
  
  <pre><code>nsExec::ExecToStack 'CMD.exe /C "${INSTDIR}\script\settingsLocation.bat" "${INSTDIR}" $SettingsDirType $SettingsDirName'
  </code></pre>
  
  <p>I get :</p>
  
  <pre><code>'C:\Program' is not recognized as an internal command, operable program or batch file.
  </code></pre>
  
  <p>Clearly I'm falling between the 2 stools of non expansion and full expanion ignoring quotes. </p>
  
  <p>How can I preserve the quotes such that the command would run as if it were typed manually as follows:</p>
  
  <pre><code>"C:\Program Files (x86)\Prog Name\script\settingsLocation.bat" "C:\Program Files (x86)\Prog Name" DTYPE DNAME
  </code></pre>
  
  <p><strong>Update 1 (following Anders's reply):</strong></p>
  
  <p>I tried the following mod:</p>
  
  <pre><code>   nsExec::ExecToStack 'CMD.exe /C "$INSTDIR\script\settingsLocation.bat" "$INSTDIR" $SettingsDirType $SettingsDirName'
  </code></pre>
  
  <p>i.e change <code>${INSTDIR}</code> to <code>$INSTDIR</code></p>
  
  <p>This gives :</p>
  
  <p><code>'C:\Program' is not recognized as a internal or external command</code></p>
  
  <p><strong>Update 2</strong></p>
  
  <p>Tried escaping the inner double quotes as follows:</p>
  
  <pre><code>   nsExec::ExecToStack 'CMD.exe /C \"$INSTDIR\script\settingsLocation.bat\" \"$INSTDIR\" $SettingsDirType $SettingsDirName'
  </code></pre>
  
  <p>But this gave:</p>
  
  <p><code>'\"C:\Program Files\....\" is not a recognised as an internal; or external command,</code></p>
  
  <p><strong>Update 3 (Resolved!!)</strong></p>
  
  <p>Following further help from Anders below, adding the <code>if 1==1</code> bit finally got it working:</p>
  
  <pre><code>   nsExec::ExecToStack 'CMD.exe /C if 1==1 "$INSTDIR\script\settingsLocation.bat" "$INSTDIR" $SettingsDirType $SettingsDirName'
  </code></pre>