The correct solution depends strongly on what the script is outputting. I would note that
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
to check the output string whole hog. We could help with that if you gave us sample outputs for success and failures.