Various ways of accomplishing the effect that you are looking for:
- Use ">/tmp/command.out 2>/tmp/command.err" in the shell command string. Read the files after the command completes, and remove the files.
- Use IPC::Open3() and select() to monitor all pipes, reading data from pipes that have data ready.
- Spawn a thread off to read data from each sub process pipe. The thread would update a shared variable as data arrived on the pipe. The thread would exit when the pipe was closed.
In order to decide which method would work best, many factors need to be analyzed, including the acceptable level of complexity of the final product, the efficiency of the product, the purpose for capturing stdout/stderr, and the host environment (UNIX vs WIN32).