Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 xp_cmdshell winzip

Author  Topic 

cottage125
Starting Member

32 Posts

Posted - 2011-04-27 : 19:34:40
hello

I have this cmd

declare @cmd varchar(2000)
select @cmd
= 'C:\"Program Files (x86)"\WinZip\wzzip.exe' + ' -whs ' + ' -ez ' + ' -rP ' + 'F:\restore\testfile.zip' + ' ' + 'F:\restore\abc.txt > C:\output.log'
print @cmd
exec master..xp_cmdshell @cmd

(http://kb.winzip.com/kb/entry/166/)

But it never overwrites output file. I tried with -o switch as well but its not overwriting. I have winzip 12.0. Can someone please tell me how to do that?

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-04-27 : 21:06:49
Open a command window and run the same command to see if it is able to overwrite the existing file. If it does not, check if the output file is readonly.

If it does work from the command line then remove the output file and run it from xp_cmdshell to see if the file can be created from xp_cmdshell in the absence of an existing file.
Go to Top of Page

cottage125
Starting Member

32 Posts

Posted - 2011-04-28 : 10:06:09
Thanks for the reply. My mistake to original post. I dont want it to overwrite..

Yes as i m sysadmin, the file is created and updated everytime when i run this command. so lets say if i run this command 5 times then log file should have the info for all 5 times but it overwrites the previous thing which i dont want.
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-04-28 : 10:16:51
Would this work for you (see change in red)?
declare @cmd varchar(2000)
select @cmd
= 'C:\"Program Files (x86)"\WinZip\wzzip.exe' + ' -whs ' + ' -ez ' + ' -rP ' + 'F:\restore\testfile.zip' + ' ' + 'F:\restore\abc.txt >> C:\output.log'
print @cmd
exec master..xp_cmdshell @cmd

My change is almost invisible, but it is replacing the single ">" with two as in ">>"
Go to Top of Page

cottage125
Starting Member

32 Posts

Posted - 2011-04-28 : 10:42:03
Wow, that simple change worked for me. I really appreciate your help sunita. Thanks a lot. This will definately help me resolve my tuff problem where we use wzzip cmd line inside cursor and that cursor zips .bak files one after other and it runs perfectly fine some days but it quits in the middle some days so it zips 2 files instead of 4 files. but the log will help me find that. Thanks
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-04-28 : 10:52:16
Take a look at the DOS "for" command. I blogged about it a long time ago:

http://weblogs.sqlteam.com/robv/archive/2003/09/28/181.aspx
http://weblogs.sqlteam.com/robv/articles/4099.aspx

You could process an entire folder with one xp_cmdshell call and no cursors. You should also research the "forfiles" command too, it's specific to file operations and has more options.
Go to Top of Page
   

- Advertisement -