0

how can I get the exit code of a 7zip's operation?

for example:

7z x filename.zip -y

how can I get it?

at now, I do some operations in bat, but I can change language.

I found something with AHK but I cannot use that language.

ps: I'm on win server 2008 r2

rschirin
  • 1,939
  • 10
  • 34
  • 44
  • Google on "7zip errorlevels" – foxidrive May 08 '13 at 12:39
  • how is populated errorlevels variable in concurrency?what I mean, how can I be sure that if I do echo %errorlevel% I see the exit code of 7z's operation and not of another program? – rschirin May 08 '13 at 12:59
  • @rschirin `ErrorLevel` will be populated with the error code from the last command executed. If you were to check the ErrorLevel on the line right after the 7zip command, ErrorLevel will be populated with 7zip's exit code. – David Ruhmann May 08 '13 at 13:56

3 Answers3

2

ErrorLevel will be populated with the error code from the last command executed. If you were to check the ErrorLevel on the line right after the 7zip command, ErrorLevel will be populated with 7zip's exit code.

7z x filename.zip -y
echo %ErrorLevel%

This above will echo 7zip's exit code


7z x filename.zip -y
set "ExitCode=%ErrorLevel%"
echo %ErrorLevel%

This above will echo set's exit code


7z x filename.zip -y
set "ExitCode=%ErrorLevel%"
echo %ExitCode%

This above will echo 7zip's exit code

David Ruhmann
  • 11,064
  • 4
  • 37
  • 47
1

You could try using the $LastExitCode variable in PowerShell to find out the exit code of your command. It returns the exit code of the last Windows based program that was run.

For example

cmd /C exit 1

Write-Host $LastExitCode # 1

Serban Constantin
  • 3,316
  • 1
  • 18
  • 20
  • when you say "the last windows based program runned" what you specifically mean?if 7zip finishes its operation and immediately another program ended (before I check $LastExitCode), in $LastExitCode what I will find? – rschirin May 08 '13 at 13:03
  • @rschirin, in that case you will find the exit code for the program that ended right after 7zip (the one between running 7zip and writing the LastExitCode). – Serban Constantin May 08 '13 at 14:49
1

Example (batch):

7z x filename.zip -y
echo(%errorlevel%
Endoro
  • 37,015
  • 8
  • 50
  • 63