code: def _exec_command_to_file(adb_cmd, dest_file_handler):
      
      t = tempfile.TemporaryFile()
      final_adb_cmd = []
      for e in adb_cmd:
          if e != '':  # avoid items with empty string...
              final_adb_cmd.append(e)  # ... so that final command doesn't
              # contain extra spaces
      print('\n*** Executing ' + ' '.join(adb_cmd) + ' ' + 'command')
  
      try:
          output = call(final_adb_cmd, stdout=dest_file_handler, stderr=t)
      except CalledProcessError as e:
          t.seek(0)
          result = e.returncode, t.read()
      else:
          result = output
          dest_file_handler.close()
  
      return result
docs: Format adb command and execute it in shell and redirects to a file
      :param adb_cmd: list adb command to execute
      :param dest_file_handler: file handler to which output will be redirected
      :return: string '0' and writes shell command output to file if successful, otherwise
      raise CalledProcessError exception and return error code