您的位置:首页 > 编程语言 > Python开发

python 杀进程 判断文件是否存在 查看进程

2015-08-07 16:33 597 查看
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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: