Monks,
I have a situation in which I want to search command output for lines containing any of a specified list of strings. I have scoured the net, Perl docs, and written the code below that is still not working. Can someone please help me understand where I am going wrong?
use constant { TRUE => 1, FALSE => 0 }; our $SUCCESS = 0; our %ErrorStrings = ( "No such file or directory" => TRUE, "does not exist in file" => TRUE, ); # Run command. @Output = qx { command here 2>&1 }; $RetCode1=$?; # If the return was success, we need to scan the output for errors. if ($RetCode1 == $SUCCESS) { # Scan the output and build a list of errors. my @FileErrors = grep { exists $ErrorStrings{$_} } @Output; if (@FileErrors) { $RetCode1 = scalar(@FileErrors); printf "Errors found: [%d] ", $RetCode1; push (@ProcErrors, @FileErrors); } # Non success error code. } else { printf "Error Code: [%d] ", $RetCode1; } # Output a status. printf "%-15s\n", ($RetCode1 == 0) ? "SUCCESS":"FAILED";
Which produces:
Processing A_Ra -> A/R ... SUCCESS Processing ADDRESS -> ADDRESS ... SUCCESS Processing ADJ-HIST -> ADJ-HIST ... SUCCESS Processing ALT-PN -> ALT-PN ... SUCCESS Processing AR-LEDGER -> AR-LEDGER ... SUCCESS Processing AR_LEVEL -> AR/LEVEL ... SUCCESS Processing BCBI -> BCBI ... SUCCESS Processing BID -> BID ... SUCCESS Processing BUDGET -> BUDGET ... SUCCESS Processing BUDGET_HEADER -> BUDGET/HEADER ... SUCCESS
And I have intentionally introduced an error into the command being called. What's more, the output of the command with the error is below:
'XORDER' does not exist in file. Open file error.
Please help me understand what I am doing wrong.
Thank you
In reply to Confusion with finding strings in command output by pgduke65
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |