Helper method to collect the command output as string.