I’m trying to capture standard output of a command to a file-like object in Perl.
I essentially need to do the following:
- Execute an OS command, capturing standard output.
- Run a regular expression on each line of the file and pull output into an array.
- Call another OS command for each item in the array of lines of output from the first command.
How can I do step one? I’d like to execute a command and get its standard out in a filelike object so as to be able to read it line by line.
The first part is easy:
Clearly, the remainder is not much harder:
Automatic error checking for the
openandsystemcalls is provided throughautodie.