handle command failure; fix write_command_to_file