当前位置: 首页>>代码示例>>Python>>正文


Python subprocess.getoutput方法代码示例

本文整理汇总了Python中subprocess.getoutput方法的典型用法代码示例。如果您正苦于以下问题:Python subprocess.getoutput方法的具体用法?Python subprocess.getoutput怎么用?Python subprocess.getoutput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在subprocess的用法示例。


在下文中一共展示了subprocess.getoutput方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_token

# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import getoutput [as 别名]
def get_token(oc_path):
    """
    Get authentication token from OC command line tool

    Returns:
    The bearer token to the init_setup function

    """
    global USER_NAME, PASSWORD, IP
    print("Logging into your OpenShift Cluster")
    status, _ = subprocess.getstatusoutput(oc_path + "oc login "+IP+" -u "+USER_NAME+" -p "+ \
        PASSWORD +" --insecure-skip-tls-verify=true")
    if status == 0:
        print("Successfully logged into the OpenShift Cluster")
    else:
        print("Could not login, please enter correct login credentials")
        exit(1)
    token = subprocess.getoutput(oc_path + "oc whoami -t")

    return token

#General Function for get calls 
开发者ID:HewlettPackard,项目名称:hpe-solutions-openshift,代码行数:24,代码来源:operator_install.py

示例2: process_output

# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import getoutput [as 别名]
def process_output(self, cmds):
        """
        Not really any output to process with this module, but you need to cwd into directory to make database generation work, so
        I'll do that here.
        """

        cwd = os.getcwd()
        ver_pat = re.compile("gowitness:\s?(?P<ver>\d+\.\d+\.\d+)")
        version = subprocess.getoutput("gowitness version")
        command_change = LooseVersion("1.0.8")
        gen_command = ["report", "generate"]
        m = ver_pat.match(version)
        if m:
            if LooseVersion(m.group("ver")) <= command_change:
                gen_command = ["generate"]
        for cmd in cmds:
            output = cmd["output"]

            cmd = [self.binary] + gen_command
            os.chdir(output)

            subprocess.Popen(cmd, shell=False).wait()
            os.chdir(cwd)

        self.IPAddress.commit() 
开发者ID:depthsecurity,项目名称:armory,代码行数:27,代码来源:Gowitness.py

示例3: get_worker_versions

# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import getoutput [as 别名]
def get_worker_versions():
    """ Search and return the versions of Oasis components
    """
    ktool_ver_str = subprocess.getoutput('fmcalc -v')
    plat_ver_file = '/home/worker/VERSION'

    if os.path.isfile(plat_ver_file):
        with open(plat_ver_file, 'r') as f:
            plat_ver_str = f.read().strip()
    else:
        plat_ver_str = ""

    return {
        "oasislmf": mdk_version,
        "ktools": ktool_ver_str,
        "platform": plat_ver_str
    }


# When a worker connects send a task to the worker-monitor to register a new model 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:22,代码来源:tasks.py

示例4: _learn

# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import getoutput [as 别名]
def _learn(self, irc, msg, channel, text, probability):
        """Internal method for learning phrases."""
        text = self._processText(channel, text)  # Run text ignores/strips/cleanup.
        if os.path.exists(self._getBrainDirectoryForChannel(channel)):
            # Does this channel have a directory for the brain file stored and does this file exist?
            if text:
                self.log.debug("Learning: {0}".format(text))
                cobeBrain = SQLiteBrain(self._getBrainDirectoryForChannel(channel))
                cobeBrain.learn(text)
                if random.randint(0, 10000) <= probability:
                    self._reply(irc, msg, channel, text)
        else:  # Nope, let's make it!
            subprocess.getoutput("{0} {1}".format(self._doCommand(channel), "init"))
            if text:
                self.log.debug("Learning: {0}".format(text))
                cobeBrain = SQLiteBrain(self._getBrainDirectoryForChannel(channel))
                cobeBrain.learn(text)
                if random.randint(0, 10000) <= probability:
                    self._reply(irc, msg, channel, text) 
开发者ID:oddluck,项目名称:limnoria-plugins,代码行数:21,代码来源:plugin.py

示例5: test_getoutput

# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import getoutput [as 别名]
def test_getoutput(self):
        self.assertEqual(subprocess.getoutput('echo xyzzy'), 'xyzzy')
        self.assertEqual(subprocess.getstatusoutput('echo xyzzy'),
                         (0, 'xyzzy'))

        # we use mkdtemp in the next line to create an empty directory
        # under our exclusive control; from that, we can invent a pathname
        # that we _know_ won't exist.  This is guaranteed to fail.
        dir = None
        try:
            dir = tempfile.mkdtemp()
            name = os.path.join(dir, "foo")
            status, output = subprocess.getstatusoutput(
                ("type " if mswindows else "cat ") + name)
            self.assertNotEqual(status, 0)
        finally:
            if dir is not None:
                os.rmdir(dir) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:20,代码来源:test_subprocess.py

示例6: load_command

# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import getoutput [as 别名]
def load_command(self):  # pragma: no cover
        """Run the command in state and get the output
        
        Returns:
            Chepy: The Chepy object. 

        Examples:
            This method can be used to interace with the shell and Chepy 
            directly by ingesting a commands output in Chepy. 

            >>> c = Chepy("ls -l").shell_output().o
            test.html
            ...
            test.py
        """
        self.state = subprocess.getoutput(self.state)
        return self 
开发者ID:securisec,项目名称:chepy,代码行数:19,代码来源:core.py

示例7: parse_log

# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import getoutput [as 别名]
def parse_log(file):
    """
    解析log文件,画出阻塞率的变化曲线
    :param file:
    :return:
    """
    prefix = 'bash'
    log_file = os.path.join(prefix, file)
    out = sp.getoutput("cat {}| grep remain".format(log_file))
    out = out.split('\n')
    y = []
    for i in out:
        tmp = i.split(' ')[26]
        tmp = tmp.split('=')[1]
        y.append(float(tmp))
    plt.plot(y) 
开发者ID:BoyuanYan,项目名称:Actor-Critic-Based-Resource-Allocation-for-Multimodal-Optical-Networks,代码行数:18,代码来源:utils.py

示例8: hci_write_local_name

# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import getoutput [as 别名]
def hci_write_local_name(params:bytes, iface='hci0'):
    ogf = HCI_CTRL_BASEBAND_CMD_OGF
    ocf = 0x0013

    params = ' '.join([hex(b) for b in params])
    hcitool_cmd = gen_hcitool_cmd(ogf, ocf, params, iface)

    print(subprocess.getoutput(hcitool_cmd)) 
开发者ID:fO-000,项目名称:bluescan,代码行数:10,代码来源:hci.py

示例9: hci_link_Key_request_reply

# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import getoutput [as 别名]
def hci_link_Key_request_reply(bd_addr:str, link_key:str, iface='hci0'):
    '''BLUETOOTH CORE SPECIFICATION Version 5.1 | Vol 2, Part E page 825, 7.1.10 Link Key Request Reply command'''
    ogf = LINK_CTRL_CMD_OGF
    ocf = 0x000B

    # HCI command parameter using litten-endian
    bd_addr = ' '.join(['0x' + e for e in bd_addr.split(':')[::-1]])
    print(bd_addr)
    link_key = ' '.join([hex(b) for b in bytes.fromhex(link_key)])
    print(link_key)

    params = bd_addr + ' ' + link_key
    hcitool_cmd = gen_hcitool_cmd(ogf, ocf, params, iface)

    print(subprocess.getoutput(hcitool_cmd)) 
开发者ID:fO-000,项目名称:bluescan,代码行数:17,代码来源:hci.py

示例10: hci_read_stored_link_key

# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import getoutput [as 别名]
def hci_read_stored_link_key(bd_addr='00:00:00:00:00:00', read_all_flag=0x01, iface='hci0'):
    '''BLUETOOTH CORE SPECIFICATION Version 5.1 | Vol 2, Part E page 966, 7.3.8 Read Stored Link Key command'''
    ogf = HCI_CTRL_BASEBAND_CMD_OGF
    ocf = 0x000D
    
    bd_addr = ' '.join(['0x' + e for e in bd_addr.split(':')[::-1]])
    read_all_flag = hex(read_all_flag)

    params = ' '.join([bd_addr, read_all_flag])

    hcitool_cmd = gen_hcitool_cmd(ogf, ocf, params, iface)
    print(subprocess.getoutput(hcitool_cmd)) 
开发者ID:fO-000,项目名称:bluescan,代码行数:14,代码来源:hci.py

示例11: hci_write_stored_link_key

# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import getoutput [as 别名]
def hci_write_stored_link_key(bd_addrs: list, link_keys:list, iface='hci0'):
    '''BLUETOOTH CORE SPECIFICATION Version 5.1 | Vol 2, Part E page 968, 7.3.9 Write Stored Link Key command.'''
    ogf = HCI_CTRL_BASEBAND_CMD_OGF
    ocf = 0x0011

    if (len(bd_addrs) != len(link_keys)):
        print("[ERROR] BD_ADDRs and Link Keys is not one-to-one correspondence.")
        return False
    
    num_keys_to_write = len(link_keys)

    temp = ''
    for bd_addr in bd_addrs:
        temp +=  ' '.join(
            ['0x' + e for e in bd_addr.split(':')[::-1]]
    ) + ' '
    bd_addrs = temp
    print(bd_addrs)

    temp = ''
    for link_key in link_keys:
        temp += ' '.join(
        [hex(b) for b in bytes.fromhex(link_key)]
    ) + ' '
    link_keys = temp
    print(link_keys)

    params = hex(num_keys_to_write) + ' ' + bd_addrs + ' ' \
        + link_keys

    hcitool_cmd = gen_hcitool_cmd(ogf, ocf, params, iface)
    print(subprocess.getoutput(hcitool_cmd)) 
开发者ID:fO-000,项目名称:bluescan,代码行数:34,代码来源:hci.py

示例12: hci_delete_stored_link_key

# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import getoutput [as 别名]
def hci_delete_stored_link_key(bd_addr='00:00:00:00:00:00', del_all_flag=0x01, iface='hci0'):
    "BLUETOOTH CORE SPECIFICATION Version 5.1 | Vol 2, Part E page 970, 7.3.10 Delete Stored Link Key command"
    ogf = HCI_CTRL_BASEBAND_CMD_OGF
    ocf = 0x0012

    bd_addr = ' '.join(['0x' + e for e in bd_addr.split(':')[::-1]])
    del_all_flag = hex(del_all_flag)
    params = ' '.join([bd_addr, del_all_flag])

    hcitool_cmd = gen_hcitool_cmd(ogf, ocf, params)
    print(subprocess.getoutput(hcitool_cmd)) 
开发者ID:fO-000,项目名称:bluescan,代码行数:13,代码来源:hci.py

示例13: _init_dist_slurm

# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import getoutput [as 别名]
def _init_dist_slurm(backend, port=29500, **kwargs):
    proc_id = int(os.environ['SLURM_PROCID'])
    ntasks = int(os.environ['SLURM_NTASKS'])
    node_list = os.environ['SLURM_NODELIST']
    num_gpus = torch.cuda.device_count()
    torch.cuda.set_device(proc_id % num_gpus)
    addr = subprocess.getoutput(
        'scontrol show hostname {} | head -n1'.format(node_list))
    os.environ['MASTER_PORT'] = str(port)
    os.environ['MASTER_ADDR'] = addr
    os.environ['WORLD_SIZE'] = str(ntasks)
    os.environ['RANK'] = str(proc_id)
    dist.init_process_group(backend=backend) 
开发者ID:dingjiansw101,项目名称:AerialDetection,代码行数:15,代码来源:env.py

示例14: run

# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import getoutput [as 别名]
def run(command):
    if DEBUG:
        print(command)
    else:
        return subprocess.getoutput(command)


# ------------------------------------------------------------------------------- 
开发者ID:cyanfish,项目名称:heltour,代码行数:10,代码来源:backup.py

示例15: _get_test_cases

# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import getoutput [as 别名]
def _get_test_cases(self):
        cmd = '$(find /tmp/verify -exec file {} \; | grep -i ELF | cut -d: -f1)'
        output = subprocess.getoutput(cmd)
        return output.splitlines() 
开发者ID:fkie-cad,项目名称:LuckyCAT,代码行数:6,代码来源:elf_fuzzer.py


注:本文中的subprocess.getoutput方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。