使用python执行cmd命令

1、进行app测试前都需要连接手机,使用cmd窗口执行命令:adb devices

2、使用airtest无线连接手机时需要提前执行tcpip配置:adb tcpip 48887

一、通过os.system('输入命令')来执行

import os

cmd_devices = os.system('adb devices')
print(type(cmd_devices))
print('cmd_devices:', cmd_devices)

cmd_tcpip = os.system('adb tcpip 48887')
print(type(cmd_tcpip))
print('cmd_tcpip:', cmd_tcpip)

 输出结果:

PS:执行成功,但输出的结果返回值为int类型的0,表示执行成功,此时无法获取到其他的返回信息。

 

 二、通过os.popen('输入命令')来执行

cmd_devices = os.popen('adb devices')
print(type(cmd_devices))
#输出返回的类型是对象类型,通过read()方法读出返回值
print('cmd_devices:', cmd_devices.read())

cmd_tcpip = os.popen('adb tcpip 48887')
print(type(cmd_tcpip))
#输出返回的类型是对象类型,通过read()方法读出返回值
print('cmd_tcpip:', cmd_tcpip.read())

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值