
1arryb
User
May 26, 2009, 1:42 PM
Post #2 of 3
(1601 views)
|
|
Re: [200mg] Noob ? about Regular Expressions
[In reply to]
|
Can't Post
|
|
Hi 200mg, You don't need the print to get the output of a command, so, if the standard output of winzip can contain /Error/, then:
$_ = `winzip -o c:\\begperl\\zips\\*.zip`; should suffice. However, you shouldn't use the global '$_' variable for your own data. Better would be:
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:
my $ret = `winzip -o c:\\begperl\\zips\\*.zip 2>&1`; However, since you are really only interested in whether winzip succeeded, you might try:
my $ret = `winzip -o c:\\begperl\\zips\\*.zip 2>&1`; if ( $? != 0 ) { print "winzip failed. Error was:\n"; print $ret; } Whether this will work or not depends on whether winzip exits with an error status on failure (hint: RTM). Cheers, Larry
|