Hi! My first post on this forum
The problem is this.... I have written a script that detaches, zips, and moves databases to an archive location, however I have just realised that it dosent deal with databases that have spaces in their name. As a result I have tried to enclose my db names in " " however when executed on cmd line it dosent work!?
Problem lines:
set @zipcmd = '"C:\Program Files\WinZip\wzzip" ' + '"' + @zipfilename + '" "' + @filename + '"' print @zipcmd exec xp_cmdshell @zipcmd
error returned:
'C:\Program' is not recognized as an internal or external command,operable program or batch file.
the print @zipcmd line looks perfect:
"C:\Program Files\WinZip\wzzip" "C:\Copy of An Example.zip" "C:\Copy of An Example.mdf"
Without the extra quotes(green) to deal with spaces the line works perfectly. Im guessing that Im not constructing the string properly?? Any help greatly appreciated!
Try this:
In TSQL split the path from the executable; @Path & @Exe
Create a command string and execute it:
Set @Cmd='CD /D '+@Path+' & "'+@Exe+'" '"+@Parm1+"' '"+@Parm2+'" ...'
(notice that the CD command does NOT require double-quotes around its argument; notice the & command separator; notice the double quotes around @Exe and the @Parm expansions...)
Exec master..xp_CmdShell @Cmd
Command Prompt is a quagmire of legacy convention...