Generally we run DOS commands, there are two requirements, one is the need to collect execution results, such as IP, device, etc., one does not need to collect results, such as killing or opening a service.
The corresponding two methods are encapsulated in Python to achieve both of these requirements separately.
1. Introduction Package
Import OS
2, only do not collect results
Os.system (command)
3. Execution and phone results
Os.popen (command). ReadLines ()
4. Code implementation
1 #Coding=utf-82 ImportOS3 4 classDoscmd:5 " "6 used to encapsulate Windows execution DOS commands in two ways, one is to collect execution results, and one is to not collect execution results7 " "8 defExcute_cmd_result (self,command):9 " "Ten executes command and returns the execution result One :p Aram Command: Pass in the string format to execute A : Return: Returns execution result, tabular format - " " -Result_list = [] theresult =os.popen (command). ReadLines () - forIinchResult: - ifi = ='\ n': - Continue +Result_list.append (I.strip ('\ n') ) #strip () method to remove the character specified by the tail of the string - returnresult_list + A at defExcute_cmd (self,command): - " " - execute command only and do not collect execution results - :p Aram Command: Pass in the string format to execute - " " - os.system (command) in - if __name__=="__main__": toDOS =Doscmd () + PrintDos.excute_cmd_result ('ADB devices') -Dos.excute_cmd ('ADB devices')
Appium Automated test framework-executing DOS commands in Python scripts