Python subprocess.getoutput() Examples
The following are 30 code examples for showing how to use subprocess.getoutput(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
subprocess
, or try the search function
.
Example 1
Project: hpe-solutions-openshift Author: HewlettPackard File: operator_install.py License: Apache License 2.0 | 6 votes |
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
Example 2
Project: armory Author: depthsecurity File: Gowitness.py License: GNU General Public License v3.0 | 6 votes |
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()
Example 3
Project: OasisPlatform Author: OasisLMF File: tasks.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example 4
Project: limnoria-plugins Author: oddluck File: plugin.py License: Do What The F*ck You Want To Public License | 6 votes |
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)
Example 5
Project: Fluid-Designer Author: Microvellum File: test_subprocess.py License: GNU General Public License v3.0 | 6 votes |
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)
Example 6
Project: chepy Author: securisec File: core.py License: GNU General Public License v3.0 | 6 votes |
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
Example 7
Project: Actor-Critic-Based-Resource-Allocation-for-Multimodal-Optical-Networks Author: BoyuanYan File: utils.py License: GNU General Public License v3.0 | 6 votes |
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)
Example 8
Project: ironpython3 Author: IronLanguages File: test_subprocess.py License: Apache License 2.0 | 6 votes |
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)
Example 9
Project: bluescan Author: fO-000 File: hci.py License: GNU General Public License v3.0 | 5 votes |
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))
Example 10
Project: bluescan Author: fO-000 File: hci.py License: GNU General Public License v3.0 | 5 votes |
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))
Example 11
Project: bluescan Author: fO-000 File: hci.py License: GNU General Public License v3.0 | 5 votes |
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))
Example 12
Project: bluescan Author: fO-000 File: hci.py License: GNU General Public License v3.0 | 5 votes |
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))
Example 13
Project: bluescan Author: fO-000 File: hci.py License: GNU General Public License v3.0 | 5 votes |
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))
Example 14
Project: AerialDetection Author: dingjiansw101 File: env.py License: Apache License 2.0 | 5 votes |
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)
Example 15
Project: heltour Author: cyanfish File: backup.py License: MIT License | 5 votes |
def run(command): if DEBUG: print(command) else: return subprocess.getoutput(command) # -------------------------------------------------------------------------------
Example 16
Project: LuckyCAT Author: fkie-cad File: elf_fuzzer.py License: GNU General Public License v3.0 | 5 votes |
def _get_test_cases(self): cmd = '$(find /tmp/verify -exec file {} \; | grep -i ELF | cut -d: -f1)' output = subprocess.getoutput(cmd) return output.splitlines()
Example 17
Project: DenseMatchingBenchmark Author: DeepMotionAIResearch File: env.py License: MIT License | 5 votes |
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)
Example 18
Project: reviewer_experience_prediction Author: mulhod File: setup.py License: MIT License | 5 votes |
def get_python_header_dir(): # Hackish way of doing this. Find better way... root_env = getoutput('conda info | grep "package cache :"' ' | awk \'{print $4}\'') # Try to guess the location of the conda installation if not root_env: root_env = '/home/{}/conda'.format(getuser()) return join(root_env, '.pkgs', 'python-3.4.3-0', 'include', 'python3.4m')
Example 19
Project: interSubs Author: oltodosel File: interSubs.py License: MIT License | 5 votes |
def mpv_pause_status(): stdoutdata = subprocess.getoutput('echo \'{ "command": ["get_property", "pause"] }\' | socat - "' + mpv_socket + '"') try: return loads(stdoutdata)['data'] except: return mpv_pause_status()
Example 20
Project: interSubs Author: oltodosel File: interSubs.py License: MIT License | 5 votes |
def mpv_fullscreen_status(): stdoutdata = subprocess.getoutput('echo \'{ "command": ["get_property", "fullscreen"] }\' | socat - "' + mpv_socket + '"') try: return loads(stdoutdata)['data'] except: return mpv_fullscreen_status()
Example 21
Project: interSubs Author: oltodosel File: interSubs.py License: MIT License | 5 votes |
def mpv_pause_status(): stdoutdata = subprocess.getoutput('echo \'{ "command": ["get_property", "pause"] }\' | socat - "' + mpv_socket + '"') try: return loads(stdoutdata)['data'] except: return mpv_pause_status()
Example 22
Project: interSubs Author: oltodosel File: interSubs.py License: MIT License | 5 votes |
def mpv_fullscreen_status(): # return 1 stdoutdata = subprocess.getoutput('echo \'{ "command": ["get_property", "fullscreen"] }\' | socat - "' + mpv_socket + '"') try: return loads(stdoutdata)['data'] except: return mpv_fullscreen_status()
Example 23
Project: GCNet Author: xvjiarui File: env.py License: Apache License 2.0 | 5 votes |
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)
Example 24
Project: conditional-motion-propagation Author: XiaohangZhan File: distributed_utils.py License: MIT License | 5 votes |
def _init_dist_slurm(backend, port=10086, **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)
Example 25
Project: Veil Author: Veil-Framework File: completer.py License: GNU General Public License v3.0 | 5 votes |
def complete_set(self, args): """ Complete all options for the 'set' command. """ res = [] if hasattr(self.payload, 'required_options'): options = [k for k in sorted(self.payload.required_options.keys())] if args[0] != '': if args[0].strip() == "LHOST": # autocomplete the IP for LHOST if settings.DISTRO == 'Debian': ip_output = subprocess.getoutput("ip a").split("\n")[8][9:].split('/')[0] ip_output = subprocess.getoutput("/sbin/ifconfig eth0").split("\n")[1].split()[1] if 'addr' in ip_output: ip_output = ip_output[5:] res = [ip_output] + [None] elif args[0].strip() == "LPORT": # autocomplete the common MSF port of 4444 for LPORT res = ["4444"] + [None] elif args[0].strip() == "original_exe": # tab-complete a file path for an exe res = self.complete_path(args) elif args[0].strip().endswith("_source"): # tab-complete a file path for an exe res = self.complete_path(args) # elif args[0].strip() == "other path-needing option": # # tab-complete a file path # res = self.complete_path(args) else: # complete the command in the list ONLY if it's partially completed res = [o + ' ' for o in options if (o.startswith(args[0]) and o != args[0])] + [None] else: # return all required_options available to 'set' res = [o + ' ' for o in options] + [None] return res
Example 26
Project: Veil Author: Veil-Framework File: completer.py License: GNU General Public License v3.0 | 5 votes |
def complete(self, text, state): buffer = readline.get_line_buffer() line = readline.get_line_buffer().split() if not line: if settings.DISTRO == 'Debian': ip[state] = subprocess.getoutput("ip a").split("\n")[8][9:].split('/')[0] else: ip = [subprocess.getoutput("/sbin/ifconfig eth0").split("\n")[1].split()[1]] + [None] if 'addr' in ip[state]: ip[state] = ip[state][5:] return ip[state] else: return text[state]
Example 27
Project: Veil Author: Veil-Framework File: completer.py License: GNU General Public License v3.0 | 5 votes |
def complete_set(self, args): """ Complete all options for the 'set' command. """ res = [] if hasattr(self.payload, 'required_options'): options = [k for k in sorted(self.payload.required_options.keys())] if args[0] != '': if args[0].strip() == "LHOST": if settings.DISTRO == 'Debian': ip_output = subprocess.getoutput("ip a").split("\n")[8][9:].split('/')[0] # autocomplete the IP for LHOST else: ip_output = subprocess.getoutput("/sbin/ifconfig eth0").split("\n")[1].split()[1] if 'addr' in ip_output: ip_output = ip_output[5:] res = [ip_output] + [None] elif args[0].strip() == "LPORT": # autocomplete the common MSF port of 4444 for LPORT res = ["8675"] + [None] elif args[0].strip() == "original_exe": # tab-complete a file path for an exe res = self.complete_path(args) elif args[0].strip().endswith("_source"): # tab-complete a file path for an exe res = self.complete_path(args) # elif args[0].strip() == "other path-needing option": # # tab-complete a file path # res = self.complete_path(args) else: # complete the command in the list ONLY if it's partially completed res = [o + ' ' for o in options if (o.startswith(args[0]) and o != args[0])] + [None] else: # return all required_options available to 'set' res = [o + ' ' for o in options] + [None] return res
Example 28
Project: Veil Author: Veil-Framework File: evasion_helpers.py License: GNU General Public License v3.0 | 5 votes |
def LHOST(): """ Return the IP of eth0 """ ip_output = subprocess.getoutput("/sbin/ifconfig eth0").split("\n")[1].split()[1] if 'addr' in ip_output: ip_output = ip_output[5:] return ip_output
Example 29
Project: pywasm Author: mohanson File: test_examples.py License: MIT License | 5 votes |
def test_examples(): assert subprocess.getoutput(f'{py} examples/add.py') == '9' assert subprocess.getoutput(f'{py} examples/env.py') == '55' assert subprocess.getoutput(f'{py} examples/fib.py') == '55' assert subprocess.getoutput(f'{py} examples/str.py') == 'Hello World!' assert subprocess.getoutput(f'{py} examples/sum.py') == '4950'
Example 30
Project: figma-linux-font-helper Author: tryvin File: helpers.py License: MIT License | 5 votes |
def get_font_list(): font_list = {} allowed_extensions = ('\\.ttf', '\\.ttc', '\\.otf') font_shell_command = "fc-list --format '%%{file} | %%{family} | %%{weight} | %%{style} | %%{postscriptname}\\n' | sort | grep -e '%s'" % ( "\\|".join(allowed_extensions), ) for font_line in subprocess.getoutput(font_shell_command).split("\n"): details = font_line.split(" | ") if details[0] not in font_list: font_list[details[0].strip()] = [{ "localizedFamily": details[1].split(",", 1)[0].strip(), "postscript": details[4].strip(), "style": details[3].split(",", 1)[0].strip(), "weight": details[2], "stretch": 5, "italic": True if re.match("Italic|Oblique", details[3]) else False, "family": details[1].split(",", 1)[0].strip(), "localizedStyle": details[3].split(",", 1)[0].strip() }] return font_list