Reputation: 551
echo off
if "%4" == "" goto usage
cd %3
mkdir Logs
echo Logs can be found in %3\Logs
echo
goto %4
:smmdsp
echo Updating %2..xyz table on %1
sqlcmd -S %1 -E -p -e -d %2 -i "%3\xyz.SQL" > %3\Logs\xyz.SQL.log
goto done
:usage
echo.
echo Usage
echo.
echo where SqlServer = SQL Server name
echo Database = configuration database
echo InstallPath = path to the software update files
echo Feature = Feature to update
echo.
:done
This script works if i have the batch file in C drive C:\XYZ , but if there are spaces in the path or if its in program files 86 folder C:\Program Files (x86) .It Gives out a error that says
How to handle this scenario... ?? Thank you
Upvotes: 0
Views: 14280
Reputation: 51
OK, This is the answer.
In my multiple decades of experience as a professional programmer, I have learned that most bugs that are not easily solved are not difficult because the problem itself is difficult, but because of human nature we make assumptions about the elements of our code that are simply incorrect, but we cannot "see" it because of that innate assumption. To compound that error in our own behavior, once we discover the error in our thought process we tend to be too embarrassed to tell others what the source of the issue was.
At this point in my career... I have nothing left to prove, and am more concerned with saving others the pain and waste of valuable coding time.
This is one of those insidious things that is due mostly to Microsoft being presumptuous, and removing file extensions from view by default. ...grrr I left my xanax at home today.
What I have done here, by my assuming that the file name I was trying to use as a parameter to the sqlcmd call was ... -i c:\temp\myscript.sql
and I was completely wrong. The file I was trying to reference was
c:\temp\myscript.sql.txt
but Microsoft in their attempt to try to help me removed the actual extension from view in file explorer and fooled me into thinking I had the correct file name. I didn't. Once I realized that I corrected the file name, which then made my code reference correct, and everything worked perfectly.
Upvotes: 5
Reputation: 9545
Try with strings :
sqlcmd -S "%1" -E -p -e -d %2 -i "%3\xyz.SQL" > %3\Logs\xyz.SQL.log
Upvotes: 1