SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 
        
Home       Members    Calendar    Who's On



xp_cmdshell winzip string constuction help plz Expand / Collapse
Author
Message
Posted Friday, February 17, 2006 7:15 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, December 09, 2008 9:33 AM
Points: 2, Visits: 3

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!

Post #259409
Posted Friday, February 17, 2006 7:33 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 4:30 PM
Points: 2,302, Visits: 438
Firstly add the path of the WZZIP.EXE files to the PATH environment variable. Having done so restart MSSQLSERVER and SQLSERVERAGENT. You should now be able to call WZZIP without a fully qualified path.

Personally I avoid spaces in filenames like the plague. They cause more problems than they are worth.

I have had problems with \ characters. Try using \\ instead.



========================
You will have someones eye out with that. King Harold
Post #259421
Posted Monday, February 20, 2006 8:52 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, June 11, 2009 10:24 AM
Points: 141, Visits: 168

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...




Regards,

PeteK

Post #259917
Posted Monday, December 29, 2008 12:48 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, June 24, 2009 11:25 AM
Points: 20, Visits: 88
David.Poole (2/17/2006)
Firstly add the path of the WZZIP.EXE files to the PATH environment variable. Having done so restart MSSQLSERVER and SQLSERVERAGENT. You should now be able to call WZZIP without a fully qualified path.

Personally I avoid spaces in filenames like the plague. They cause more problems than they are worth.

I have had problems with \ characters. Try using \\ instead.


I am having the same problem. But I do not get add the path of the WZZIP.EXE and the restart MSSQL & SQL Agent

I have tried c:\Program Files\Winzip\WZZIP.exe and that does not work either.

Post #626781
Posted Wednesday, December 31, 2008 8:27 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, June 24, 2009 11:25 AM
Points: 20, Visits: 88
I have added C:\Program Files\Winzip to the path on my pc. I remoted to the server and added the path to the server that SQL Server 2005 is running on.

1. Open System from the Control Panel to the Advanced tab

2. Click the Environment Variables button

3. In the System variables section of the dialog that opens ( lower half) click Path to select it and click Edit

4. Move to the end of the text in the Variable value text box, enter a semicolon (;) and type C:\Program Files\WinZip

5. Click OK in all three open dialogs to close them

These are per the instructions of WINZIP tech.

How ever when I try to run this as a SQL statement

Declare @Work varchar(2000)
set @work= 'WZZIP G:\Production\Backups\Test.zip G:\Production\Input\*.*'
Execute xp_cmdshell @work

It does not work

If I try to run it as a SQl AGent Job it does not work

If I copy the text with in the Quoates and paste it into a dos command box it works



Post #628111
« Prev Topic | Next Topic »


Permissions Expand / Collapse