Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return non-zero exit code on error #177

Closed
homes32 opened this issue Sep 19, 2022 · 2 comments
Closed

Return non-zero exit code on error #177

homes32 opened this issue Sep 19, 2022 · 2 comments

Comments

@homes32
Copy link

homes32 commented Sep 19, 2022

I would love for the cli version to return a non-zero exit code when an error is encountered. Currently if I am extracting a file via a script there is no way my script can tell if the operation failed and make a decision on what to do next.

Example:

0 - Success
1 - MSI file not found
2 - Extraction failed
3 - File not found in MSI
...

@activescott
Copy link
Owner

Great suggestion. I'd welcome a PR and be happy to support you if you're interested in adding it. I'll put this high on the list though as I can see how it'd be super useful. Thank you for taking the time to leave the suggestion!

@activescott
Copy link
Owner

This seems to mostly work - albeit not with the specific error codes you wanted. Here is what I tested:

@setlocal

set "errorlevel=1"
set "errorlevel="

rmdir /s /q .\temp-out
mkdir .\temp-out

REM "C:\Users\User\Desktop\lessmsi-v1.6.201\lessmsi.exe" x "TestFiles\MsiInput\NUnit-2.5.2.9222.msi" temp-out
"C:\Users\User\Desktop\lessmsi-v1.6.201\lessmsi.exe" x "TestFiles\MsiInput\VBRuntime.msi" temp-out

if %errorlevel% neq 0 (echo error level is non-zero. It was %errorlevel%) else (echo error level is zero.)

Note the somewhat special way of checking errorlevel because it returns negative errorlevels (hat tip to https://stackoverflow.com/questions/10935693/foolproof-way-to-check-for-nonzero-error-return-code-in-windows-batch-file).

If I test with VBRuntime.msi (which I know to always fail) the script writes: error level is non-zero. It was -1073741819

If I use the Nunit-2.....msi the script writes: error level is zero.

So I think the basic case works here. However, I did some quick looking and getting tot he point of detecting each scenario you mentioned is a fair bit of work (mostly testing).

I'm going to close this one, but if you want feel free to tag me on it and suggest re-opening if I'm missing something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants