If a process hangs how do we get the output with popen

If a process hangs how do we get the output with popen

This is problem we have observed. Could be we need to use :close() at the end of invocation of the command: