I got the following vbscript test code that zip some test files via WinZip Command Line:
Dim strWinZipDir, strZipFileToCreate, strFilesToZip, strWinZip, strCommand
strWinZipDir = "C:\Program Files\WinZip\Winzip32.exe"
strZipFileToCreate = "C:\Users\ext_dirmod_01\Desktop\TestLog.zip"
strFilesToZip = """C:\Users\ext_dirmod_01\Desktop\FacturasGRA.vbs"" ""C:\Users\ext_dirmod_01\Desktop\Test Zip Windows.vbs"""
Set objFSO = CreateObject("Scripting.FileSystemObject")
strWinZip = objFSO.GetFile(strWinZipDir).ShortPath
strCommand = strWinzip & " -min -a -r """ & strZipFileToCreate & """ " & strFilesToZip
Set objShell = CreateObject("WScript.Shell")
Set objExec = objShell.Exec(strCommand)
Do While objExec.Status = 0
Loop
What I want to do is log the run of the zip process both for successful completion and for error/s appearance. In case of error what I want to do is get the exact message that the WinZip returns.
I have tried several ways:
>
) with a filename at the end of the command line as it was suggested in this link. This method doesn't write anything on the file.Does anyone know what else I can/should try?
As @CheranShunmugavel pointed out in a comment to another answer the knowledge base article refers to the WinZip Command Line utility. If you want to work with WinZip on the command line I strongly recommend you get that add-on, even though the regular WinZip executable does support some basic command line parameters.
Note that if you want to use output redirection (>
) you must run the command in CMD, because redirection is provided by the command interpreter. For simplified handling I would also recommend using the Run
method rather than the Exec
method unless you need to programatically read from STDOUT and/or STDERR.
Set objShell = CreateObject("WScript.Shell")
rc = objShell.Run("cmd /c " & strCommand & " >C:\path\to\your.log 2>&1", 0, True)
If rc <> 0 Then WScript.Echo "An error occurred (" & rc & ")."
WScript.Quit rc