def thread_work(client_exe_path, msg): # create a process to execute the client_exe # TODO: add execute timeout _cmd = '%s %s' % (client_exe_path, msg) cmd = WrapCommand(_cmd) cmd.start() logger.debug('Start command start %s' % _cmd) cmd.join() logger.debug('Start command end %s' % _cmd) return cmd
def run_now(self, commands): """ Command run method :param commands: All command list :return: None """ for command in commands: command_obj = WrapCommand(command, shell=True) command_obj.start() command_obj.join() if command_obj.returncode != 0: self.__log_object.log_error_now(command, command_obj.results) else: self.__log_object.log_output(command, command_obj.results)
def execute_adb_cmd(cmd='adb devices'): ''' execute adb command return a tuple (stdoutdata, stderrdata) ''' idx = cmd.find('adb') if idx == -1: print 'must contain adb in cmd' return False, False cmd = cmd[idx + 3:] print ADB, cmd cmd2 = WrapCommand('%s %s' % (ADB, cmd)) cmd2.start() cmd2.join() return cmd2.results
def connect_and_check(): '''check adb devices connect or not''' adb = WrapCommand('%s devices' % ADB, shell=True) adb.start() i = 5 while i > 0 and adb.is_alive(): i -= 1 time.sleep(1) if adb.is_alive(): adb.stop() print 'adb111' adb.join() print adb.results for line in adb.results[0].split(os.linesep): if line.endswith("device") or line.endswith("recovery"): return True return False
def adb_kill_server(): ''' adb kill-server''' cmd = WrapCommand('%s kill-server' % ADB, shell=True) cmd.start() cmd.join()
#!/usr/bin/env python from commandwrapper import WrapCommand # ls -l | grep and | wc -l if 1: Ls = WrapCommand('ls -l') GrepAnd = WrapCommand('grep and') Wc = WrapCommand('wc -l') Wc.stdin = GrepAnd GrepAnd.stdin = Ls Wc.start() Wc.join() print Wc.results # ls -l | grep and | wc -l if 1: Ls = WrapCommand('ls -l | grep and | wc -l', shell=True) Ls.start() Ls.join() print Ls.results