Share p.communicate alternative logic between exec_command and put_file