I am trying to run winzip via command line and then parse the output for the word "Error" and I am wondering why what I have will not work, I have purposefully placed a corrupted zip file into a folder containing several zip files and the wzunzip output says the word "Error" in the 2nd line, but when I try the following it just shows the output of running wzunzip and not the following part that should confirm the word "Error" is in the output.

Here is a sample of the wzunzip output, after playing with it for a while i think this is happening because it doesn't read past the empty lines, i think it's only reading "Zip file: c:\begperl\zips\1.zip" and then stops.

You don't need the print to get the output of a command, so, if the standard output of winzip can contain /Error/, then:

Code

$_ = `winzip -o c:\\begperl\\zips\\*.zip`;

should suffice.

However, you shouldn't use the global '$_' variable for your own data. Better would be:

Code

my $ret = `winzip -o c:\\begperl\\zips\\*.zip`;

However, Perl backticks (``) only give you the standard output from the command. Since you are looking for an error string, you may only find it on the standard error file descriptor, not the standard output. If you were using L/Unix or running your script from a cygwin bash window, you could redirect stderr to stdout. Then /Error/ would be guaranteed to be in the backtick output:

Code

my $ret = `winzip -o c:\\begperl\\zips\\*.zip 2>&1`;

However, since you are really only interested in whether winzip succeeded, you might try:

Winzip does show the error in the regular backtick output & Winzip does not exit on error, instead it logs the error and then keeps on unzipping whatever files are left. What I am trying to do is make a script that is aware of corrupted zip files, deletes them and emails the originator that the file was corrupted and to please re-up the file. I waited too long to learn a prog. lang and decided I would start with perl. So far so good. I log the output to a txt file that I parse for the word "Error" and then print the line containing the word error to another file and make that text a variable. I will be able to pass that variable to a windows command to delete the file. Now I have to work on getting that captured filename into the subject line of an email. Here is what I have so far. I am a super noob at this so it probably looks bad to a guru but it works =)