请尝试以下操作:
import os import subprocess import timeprint ('Current Directory: {}'.format(os.getcwd()) ) print ('Opening Android SDK...') os.chdir('C:\android-sdk\platform-tools') print ('Current Directory: {}'.format(os.getcwd()) )t = str(time.ctime()) try: process_output = subprocess.check_output(["adb", "devices", "-l"])except: #Add here the type of exception you want to raise and logic print("Please check your ADB installation and syntax.")s = ('{} Checking for connected devices: {}'.format(t,process_output) ) with open('logfile.txt', 'w') as f: f.write(s)


