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

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.

Replies are listed 'Best First'.
Re^4: How to monitor/look for output?
by scottdware (Sexton) on Jun 04, 2009 at 13:06 UTC

    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`;