zoukankan      html  css  js  c++  java
  • python-(subprocess, commands)

    class Exe_local_command():
    def __init__(self, command):
    '''

    :param command:
    '''
    self.command = command
    def exe_command(self):
    '''

    :return:
    '''
    exitstatus, exitresult = commands.getstatusoutput(self.command)
    return exitstatus, exitresult

    def find_shell(self):
    '''
    @summary:find: find_command = 'find /tmp/atp1 -name "*.log.*"'
    :return:
    '''
    find_status, find_result = self.exe_command()
    if find_status == 0 and len(find_result) > 0 and find_result.find("No such file or directory") == -1:
    return find_result

    class Exe_remote_command():
    def __init__(self, command, ip, port, user, password):
    '''

    :param command:
    '''
    self.command = command
    self.ip = ip
    self.port = port
    self.user = user
    self.password = password

    def exe_command(self):
    '''

    :return:
    '''
    completed_command = ('ssh -o StrictHostKeychecking=no -p {0} {1}@{2} "{3}"'.format(self.port, self.user, self.ip, self.command))
    if self.password != None:
    completed_command = "sshpass -p {0} {1}".format(self.password, completed_command)

    sub_process = subprocess.Popen(completed_command, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, shell=True)
    outtext = ''

    #实时获取命令执行的信息
    while sub_process.poll() is None:
    line = sub_process.stdout.readline()
    outtext += line
    line = line.strip()

    exitstatus = sub_process.returncode
  • 相关阅读:
    细数ASP.NET MVC框架的7大顶级功能
    Ubuntu 10.10更新源列表
    使用iTunes将任意mp3文件转为iPhone铃声
    简单5步,在新浪微博上关联多个博客
    在windows 7 建立一个弹出光驱的快捷方式
    中国人民太伟大了!
    Ubuntu 10.10
    du 熊填数字
    WPF学习02——XAML编译
    Debugging WPF data bindings
  • 原文地址:https://www.cnblogs.com/ting152/p/12580516.html
Copyright © 2011-2022 走看看