in reply to Re: How to monitor/look for output?
in thread How to monitor/look for output?

Yeah, that's how I have it setup currently. For that though, should I use a "foreach" loop to cycle through the lines of the output and look for certain output, or what do you think would be the best way to go about that?

Replies are listed 'Best First'.
Re^3: How to monitor/look for output?
by kennethk (Abbot) on Jun 03, 2009 at 15:48 UTC
    The correct solution depends strongly on what the script is outputting. I would note that backticks return a scalar, so a foreach would be kinda pointless without splitting or some such. Likely the best choice is to think about what is different about successful vs. failing executions and craft a regular expression to check the output string whole hog. We could help with that if you gave us sample outputs for success and failures.

      Basically, the output that I would be looking for that returns from the other commands is:

      XX files copied (where XX is a number)

      Restored successfully

      If I run the commands in backticks, and have that placed in an array, like @output = `command`, would it then be best to do a foreach loop to look for that output?

        Like I said, backticks return a scalar, so you should run $output = `command`, though calling an input $output is a little confusing. Assuming that 'Restored successfully' is the last line and only returned on success, you could do something like:

        $backup_return = `command`; die "Backup failed: $backup_return\n" unless $backup_return=~/Restored + successfully/; $other_return = `second command`;