python 殺進程 判斷文件是否存在 查看進程

adb用最高權限殺進程

adb shell "su -c "kill 16276""


獲取手機目錄文件

adb shell ls mnt/shell/emulated/0/


查看進程

adb -s NX510J shell ps |find "com.kugou"


#ls //列表顯示當前文件夾內容 
#rm -r xxx //刪除名字爲xxx的文件夾及其裏面的所有文件 
#rm xxx //刪除文件xxx 
#rmdir xxx //刪除xxx的文件夾 

#mkdir -p xxx //遞歸創建xxx的文件夾
#cp [選項] [來源文件] [目的文件],-d 複製一個快捷方式/-r 複製一個目錄/-i 對一個存在的文件,詢問是否覆蓋
#mv [選項] [來源文件] [目標文件],-u 目標文件存在時纔會生效,如果源文件比目標文件新纔會移動/-i 對一個存在的文件,詢問是否覆蓋;


複製文件: 
     複製一個文件或目錄到設備: 
      adb push <source> <destination></destination></source> 
      如:adb push update.zip /sdcard/ 
     從設備上覆制一個文件或目錄: 
     adb pull <source> <destination></destination></source> 
     如:adb pull /sdcard/update.zip.


    def IsContainFile(self,strtmp):
        """判斷手機路徑下是否存在文件
        @param strtmp: 查看文件是否存在手機,多個文件用';'。默認路徑:mnt/shell/emulated/0/
        """
        strlog = ""
        strfile = strtmp.split(';')
        logcmd = "adb shell ls mnt/shell/emulated/0/"
        Popen = subprocess.Popen(logcmd, stdout=subprocess.PIPE, shell=True) 

sleep(1) //等待subprocess執行
        while True:
            next_line = Popen.stdout.readline()
            if next_line == '' and Popen.poll() != None:
                    break            
            strlog = strlog + next_line
        
        for file in strfile:
            if strlog.find(file) >= 0: 
                pass
            else:
                return False    
        return True    
     
    def GetProcess(strpro="com.kugou"):
        """獲取進程ID
        @param strpro: 進程的名字 
        """        
        logcmd = "adb shell ps |find " + '"' +strpro +'"'
        proid = []
        strtmp = []
        Popen = subprocess.Popen(logcmd, stdout=subprocess.PIPE, shell=True) 
        while True:
            next_line = Popen.stdout.readline()
            if next_line == '' and Popen.poll() != None:
                    break
            strtmp = next_line.split(' ');            
            proid.append(strtmp[3])
    
        if len(proid)>0:
            return proid
        else:
            return False     


    def killProcess(strpro):
        """獲取進程ID
        @param strpro: 進程的PID,數組
        """  
        for strtmp in strpro:
            subprocess.call('adb shell "su -c "kill %s""' %strtmp)  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章