title: Running SQLCMD from a batch file after SQLServer Install
body: <p>I've come across an odd problem, which I'm sure is easily explained and fixed.</p>
  
  <p>I'm using a .bat file to install a lot of programs, one of which is SQL server 2012 (if it matters, the other installations are just .net framework, OPOS drivers and POS software which uses SQL server).</p>
  
  <p>I can get the batch file to silently instal everything, including SQL (with SSMS), which is great.  But once SQL Server is installed I'd like to run a couple of SQL scripts to create/attach databases.</p>
  
  <p>I know that the install works (if I dont' try to doanything other than the installs), and I know that the SQLCMD works (if I run it seperately, after the install), but if I try to run the SQLCMD after the install, in the same batch file it fails with the standard 'SQLCMD is not recognised as an internal or external command...'</p>
  
  <p>I've put this down to I need to restart CMD to get it to recoginise the new command (i.e. the SQLCMD), so I figured I'd split out the SQLCMD commands into a separate batch file and call it, but it still doesn't work.  I have to physically close my original batch file down before CMD.exe picks up the new commands.</p>
  
  <p>So... is it possible to 'refresh' cmd.exe so that the newly installed SQLCMD commands are useable from the original batch file??</p>
  
  <p>Here is (some of) my script. (note that I've removed all of the other install before SQL Server)</p>
  
  <pre><code>@echo off
  SETLOCAL ENABLEDELAYEDEXPANSION
  
  "%~dp0SQLServer.exe" /QS /INDICATEPROGRESS /ACTION=install /FEATURES=SQL,SSMS /INSTANCENAME=Datasym /SECURITYMODE=SQL /SAPWD=Welcome21ST /IACCEPTSQLSERVERLICENSETERMS
  echo.
  echo SQL Server installed
  
  sqlcmd -S %computername%\DATASYM -U sa -P Welcome21ST -i %script%
  </code></pre>
  
  <p>The <code>%script%</code> variable changes (like I said, there are multiple scripts I'd like to run).  And I know that the scripts themselves work.</p>
  
  <p>Why does CMD not recognise SQLCMD as a command??</p>
  
  <p>I tried to replace the line:</p>
  
  <pre><code>sqlcmd -S %computername%\DATASYM -U sa -P Welcome21ST -i %script%
  </code></pre>
  
  <p>with</p>
  
  <pre><code>call sqlscript.bat
  </code></pre>
  
  <p>as I thought that would open another CMD,exe (which it does), so I assumed that the second CMD would see the ew command (SQLCMD), but it doesn't seem to .</p>
  
  <p>Any help on how I can get the SQLCMD to work in the original batch file would be greatly appreciated.</p>