Jump to content

Get return code from 7zip


Recommended Posts

The 7zip help file lists 6 exit codes for 7z.exe. What I am trying to do is get the code to check if the extraction completed successfully or erred.

I have tried to use the the STDOUT and STDERR streams and also the merged stream but I don't get any of the return codes listed. I only get a blank string. Is it possible to get the code this way?

Thanks

Local $Runstring = 7z.exe x "Z:\Utils\Office\Hotfixes\KB907417.exe" -aoa -o"C:\DOCUME~1\Benners\LOCALS~1\Temp\KB907417 *.msp -y
Local $Run = Run($Runstring, '', @SW_HIDE, 8)
Local $iReturnCode = 9 ; set to check if changed

While ProcessExists($Run) ; Loop while the exe is running.
    $iReturnCode = StdoutRead($run) ; also used StderrRead
    Sleep(10)
WEnd

MsgBox(0,'return', $iReturnCode)
Link to comment
Share on other sites

Why don't you simply use RunWait. Or do you need to read something with StdoutRead?

if want to use Run then take a look here

BTW: if this a microsoft hotfix, it should have an switch to extract itself.

Edited by JFX
Link to comment
Share on other sites

Your code was a bit complicated, so I simplified it. Below, I tested it and if it extracted fine, it returned zero. If the file already existed, it returned 2.

#include <Constants.au3>
$iReturnCode = RunWait("7z.exe e test.zip", @ScriptDir, "", $STDERR_CHILD + $STDOUT_CHILD)
MsgBox(0,'return', $iReturnCode)

#include <ByteMe.au3>

Link to comment
Share on other sites

Thanks for the replies.

@JFX

I have some code inside the while loop that checks the size of the folder the exe is extracted to and it updates a progress bar with the result. I looked at the link you posted and tested it with a few errors and it works.

The reason for using 7zip is there are other files besides the office ones and I can use 7zip to only extract certain file types from the archive.

@sleepydvdr

Thanks for your code, I always try to whittle down to the minimum when I have working code. The reason is above why I don't use RunWait, I need to update a progress bar with some sort of progress and the way I found was to get the dir size during extraction.

Link to comment
Share on other sites

hi,

Is there a reason why you don't want to use RunWait and 7zG.exe?

-smartee

7zG is the GUI version of 7zip. I already have a GUI for a program I am rewriting (Office Integrator) and there are progress bars that take returned values and update from them.

Cheers

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...