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?
|
|
||||
|
|
|
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
(The findstr command with switches above excludes all lines containing the words within quotes.) |
|||||||||||
|
|
7-Zip writes all its messages to stdout, including error and warning messages. This means you can collect all the output from it by redirecting stdout it to a file. This can be done by appending
After that, you should be able to parse the output file and look for the lines with "WARNING" or whatever in them. You can do this conditionally based on whether the value of According to the documentation these are the possible exit codes (
|
|||
|
|