rschirin
rschirin

Reputation: 2049

Powershell or Batch EXITCODE 7zip

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

Upvotes: 0

Views: 3273

Answers (3)

Endoro
Endoro

Reputation: 37569

Example (batch):

7z x filename.zip -y
echo(%errorlevel%

Upvotes: 1

David Ruhmann
David Ruhmann

Reputation: 11367

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

Upvotes: 2

Serban Constantin
Serban Constantin

Reputation: 3576

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

Upvotes: 1

Related Questions