How to output specific lines from a batch routine?

I have the following batch script, iterating recursively on all files in a given folder:

FOR /R %%i IN ("*.wmv") DO "C:\Program Files\7-Zipa\7za.exe" a -mx0 -tzip -pPassword -mem=AES256 -y "%%~dpni.zip" "%%i"

that, when ran, it produces the following output per each file it works on:

 7-Zip (a) [64] 16.04 : Copyright (c) 1999-2016 Igor Pavlov : 2016-10-04

 Scanning the drive:
 1 file, 382316 bytes (374 KiB)

 Creating archive: C:\test\7208969.zip

 Items to compress: 1


 Files read from disk: 1
 Archive size: 382524 bytes (374 KiB)
 Everything is Ok

What I would like is to create an output text file that only contains these two lines per iteraction:

Creating archive: C:\test\7208969.zip
Everything is Ok

I've tried calling the main batch script from another batch using something like (this is just an illustrative example):

FOR /F "(tried with skip, delims, tokens, etc)" %%G IN ('7zip.bat') DO echo %%G

but all that I've tried ended up writing lots of weird stuff, except what I needed.

If anyone could enlighten me on how to accomplish this in any way, it'll be much appreciated!.

Upvotes: 2

Views: 58

Answers (1)

Jean-François Fabre
Jean-François Fabre

Reputation: 140256

just pipe the output of your command in your loop with findstr and 2 expressions, one for each line.

FOR /R %%i IN ("*.wmv") DO "C:\Program Files\7-Zipa\7za.exe" a -mx0 -tzip -pPassword -mem=AES256 -y "%%~dpni.zip" "%%i" | findstr /C:"Creating archive" /C:"Everything"

At this point, I don't have the case where something goes wrong. Obviously you can add as many strings as you want:

... | findstr /C:"Creating archive" /C:"Everything is OK" /C:"Something went wrong"

Upvotes: 1

Related Questions