當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。