I use 7-zip (in my batch files) to pack some directory and send archive by email. When I use some file in this directory at the same time the batch file is running (I start the batch files with Task Scheduler), I see warning messages in process. After this, when the archive is ready, 7-zip displays a message like this: "WARNING: Cannot open 29 files" before sending the email. When this happens, I want to be able to set an environment variable (something like %MESSAGE%
) with the value "29 warnings in progress" and to put this message in the subject of the email. But all that can do right now is use the %ERRORLEVEL%
variable. If I can't set a %MESSAGE%
variable, is it possible to write warning messages to a file, then parse this file to extract the last line?
How to write error status for command line 7-zip in variable (or, instead, in text file)
7-zipbatchcommand line
Best Answer
I suggest you use the 7-Zip Command Line Version (7za.exe).
A command like the following will redirect all output (including from stderr) to Log.txt:
Additionally, 7-Zip returns the following exit codes which you can use in your batch file with %ERRORLEVEL%:
Edit: If you don't want such a verbose log containing all those
Compressing <filename>
lines, use this command instead:(The findstr command with switches above excludes all lines containing the words within quotes.)