本文整理汇总了Python中subprocess32.check_output方法的典型用法代码示例。如果您正苦于以下问题:Python subprocess32.check_output方法的具体用法?Python subprocess32.check_output怎么用?Python subprocess32.check_output使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类subprocess32
的用法示例。
在下文中一共展示了subprocess32.check_output方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _autodetect_unzip_command
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import check_output [as 别名]
def _autodetect_unzip_command():
unzip_cmd = None
unzip_output = None
try:
unzip_output = subprocess.check_output(["unzip", "-v"])
unzip_cmd = "unzip -q $ARCHIVE"
except subprocess.CalledProcessError as e:
pass
# On MacOS Yosemite, unzip does not support Zip64, but ditto is available.
# See: https://github.com/vivlabs/instaclone/issues/1
if not unzip_cmd or not unzip_output or unzip_output.find("ZIP64_SUPPORT") < 0:
log.debug("did not find 'unzip' with Zip64 support; trying ditto")
try:
# ditto has no simple flag to check its version and exit with 0 status code.
subprocess.check_call(["ditto", "-c", "/dev/null", tempfile.mktemp()])
unzip_cmd = "ditto -x -k $ARCHIVE ."
except subprocess.CalledProcessError as e:
log.debug("did not find ditto")
if not unzip_cmd:
raise ArchiveError("Archive handling requires 'unzip' or 'ditto' in path")
log.debug("unzip command: %s", unzip_cmd)
return unzip_cmd
示例2: _log_interfaces
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import check_output [as 别名]
def _log_interfaces(namespace):
"""
Log interface state in namespace and default namespace.
:param namespace
:type namespace str
"""
try:
if logger.isEnabledFor(logging.DEBUG):
interfaces = check_output(['ip', 'addr'])
logger.debug("Interfaces in default namespace:\n%s", interfaces)
namespaces = check_output(['ip', 'netns', 'list'])
logger.debug("Namespaces:\n%s", namespaces)
cmd = ['ip', 'netns', 'exec', str(namespace), 'ip', 'addr']
namespace_interfaces = check_output(cmd)
logger.debug("Interfaces in namespace %s:\n%s",
namespace, namespace_interfaces)
except BaseException:
# Don't exit if we hit an error logging out the interfaces.
logger.exception("Ignoring error logging interfaces")
示例3: parent_identical_or_crashes
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import check_output [as 别名]
def parent_identical_or_crashes(self, crash, parent):
# Base names
cbasename = os.path.basename(crash)
pbasename = os.path.basename(parent)
## Filter queue filenames with sig info
if self.find_crash_parent_regex.match(pbasename):
self.logr("Parent ({}) looks like crashing input!".format(pbasename))
return True
try:
diff_out = subprocess.check_output("diff -q {} {}".format(crash, parent),
stderr=subprocess.STDOUT, shell=True)
except Exception, e:
diff_out = e.output
示例4: fastq_bwa_mem_piped
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import check_output [as 别名]
def fastq_bwa_mem_piped(fastqs,i,j,t,rg,out_dir,ref_path):
output = ''
bam = out_dir+'/'+fastqs[0].rsplit('/')[-1].rsplit('.fq')[0].rsplit('_')[0]+'.%s.bam'%j
piped_mem = [bwa_mem,'-M','-t %s'%t,'-R',r"'%s'"%rg,ref_path,
'<(%s -f %s -i %s -j %s)'%(route,fastqs[0],i,j),
'<(%s -f %s -i %s -j %s)'%(route,fastqs[1],i,j),
'|',samtools_view,'-Sb','-','-@ %s'%t,
'|',sambamba_sort,'-t %s'%t,'--tmpdir=%s/temp'%out_dir,'-o',bam,'/dev/stdin'] #-@ for threads here
try:#bwa mem call here-------------------------------------------
output += subprocess.check_output(' '.join(piped_mem),
stderr=subprocess.STDOUT,
executable='/bin/bash',
shell=True)
output += subprocess.check_output(['rm','-rf','%s/temp'%out_dir])
except Exception as E:
output += str(E) #error on the call-------------------------
return bam #list of bam files to merge into next step
#|| by number of fastq files presented
示例5: CheckRG
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import check_output [as 别名]
def CheckRG(samtools,bam,out_name,result):
file = out_name+'.bam.header'
command = [samtools,'view','-SH',bam,'-o',file]
print (' '.join(command))
subprocess.check_output(' '.join(command),stderr=subprocess.STDOUT,shell=True)
result=[]
with open(file,'r') as f:
header = f.readlines()
for l in range(len(header)):
i = 0
if header[l][0:3] == "@RG":
RG = {x.split(':')[0]:x.split(':')[-1].replace('\n','') for x in header[l].split('@RG')[-1].split('\t')[1:]}
result.append(RG)
clean = ['rm','-f',file]
subprocess.check_output(' '.join(clean),stderr=subprocess.STDOUT,shell=True)
return result
示例6: checkState
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import check_output [as 别名]
def checkState(self):
"""Detects and publishes any state change"""
found = False
state = 0
arpList = subprocess.check_output(['arp', '-n']).split('\n')
# Remove blank line
arpList.pop()
# Remove title
del arpList[0]
for entry in arpList:
if entry.split()[2].lower() == self.address:
found = True
break
if found == True:
state = 1
else:
state = 0
if state != self.state:
self.state = state
self.publishState()
示例7: on_message
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import check_output [as 别名]
def on_message(self, client, userdata, msg):
"""Process a message"""
self.logger.info('Received command on {0}: {1}'.format(self.cmdTopic, msg.payload))
inArgs = msg.payload.split(' ')
cmdArgs = []
for arg in self.command.split(' '):
if arg.find(';') == -1 or arg.find('|') == -1 or arg.find('//') == -1:
cmdArgs.append(arg)
for arg in inArgs:
if arg != 'NA' and arg.find(';') == -1 and arg.find('|') == -1 and arg.find('//') == -1:
cmdArgs.append(arg)
self.logger.info('Executing command with the following arguments: {0}'.format(cmdArgs))
try:
output = subprocess.check_output(cmdArgs, shell=False, universal_newlines=True)
self.logger.info('Command results to be published to {0}\n{1}'.format(self.pubTopic, output))
self.publishImpl(output, self.pubTopic)
except subprocess.CalledProcessError as e:
self.logger.info('Command returned an error code: {0}\n{1}'.format(e.returncode, e.output))
self.publishImpl('ERROR', self.pubTopic)
示例8: test_should_trigger_on_connect_if_client_connect_valid
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import check_output [as 别名]
def test_should_trigger_on_connect_if_client_connect_valid(server_with_mocks):
node_script = '''
module.paths.push('{0}')
WebSocket = require('ws')
const SubscriptionClient =
require('subscriptions-transport-ws').SubscriptionClient
new SubscriptionClient('ws://localhost:{1}/socket')
'''.format(
os.path.join(os.path.dirname(__file__), 'node_modules'), TEST_PORT)
try:
subprocess.check_output(
['node', '-e', node_script], stderr=subprocess.STDOUT, timeout=.2)
except:
mock = server_with_mocks.get_nowait()
assert mock.name == 'on_connect'
mock.assert_called_once()
示例9: test_should_trigger_on_connect_with_correct_cxn_params
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import check_output [as 别名]
def test_should_trigger_on_connect_with_correct_cxn_params(server_with_mocks):
node_script = '''
module.paths.push('{0}')
WebSocket = require('ws')
const SubscriptionClient =
require('subscriptions-transport-ws').SubscriptionClient
const connectionParams = {{test: true}}
new SubscriptionClient('ws://localhost:{1}/socket', {{
connectionParams,
}})
'''.format(
os.path.join(os.path.dirname(__file__), 'node_modules'), TEST_PORT)
try:
subprocess.check_output(
['node', '-e', node_script], stderr=subprocess.STDOUT, timeout=.2)
except:
mock = server_with_mocks.get_nowait()
assert mock.name == 'on_connect'
mock.assert_called_once()
mock.assert_called_with({'test': True})
示例10: create_veth
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import check_output [as 别名]
def create_veth(veth_name_host, veth_name_ns_temp):
"""
Create the veth (pair).
:param veth_name_host: The name of the veth interface
:param veth_name_ns_temp: The temporary interface name of the veth that will be
moved into the namespace.
:return: None. Raises CalledProcessError on error.
"""
# Create the veth
_log.debug("Creating veth %s in temp_ns: %s", veth_name_host, veth_name_ns_temp)
check_output(['ip', 'link',
'add', veth_name_host,
'type', 'veth',
'peer', 'name', veth_name_ns_temp],
timeout=IP_CMD_TIMEOUT)
# Set the host end of the veth to 'up' so felix notices it.
check_output(['ip', 'link', 'set', veth_name_host, 'up'],
timeout=IP_CMD_TIMEOUT)
示例11: move_veth_into_ns
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import check_output [as 别名]
def move_veth_into_ns(namespace, veth_name_ns_temp, veth_name_ns):
"""
Move the veth into the namespace.
:param namespace: The Namespace to move the veth into.
:type namespace Namespace
:param veth_name_ns_temp: The temporary interface name of the veth that will be
moved into the namespace.
:param veth_name_ns: The name of the interface in the namespace.
:return: None. Raises CalledProcessError on error.
"""
with NamedNamespace(namespace) as ns:
_log.debug("Moving temp interface %s into ns %s.", veth_name_ns_temp, ns.name)
# Create the veth pair and move one end into container:
check_output(["ip", "link", "set", veth_name_ns_temp,
"netns", ns.name],
timeout=IP_CMD_TIMEOUT)
ns.check_output(["ip", "link", "set", "dev", veth_name_ns_temp,
"name", veth_name_ns])
ns.check_output(["ip", "link", "set", veth_name_ns, "up"])
示例12: check_output
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import check_output [as 别名]
def check_output(self, command):
"""
Run a command within the named namespace.
:param command: The command to run.
:param shell: Whether this is a shell command.
:param timeout: Command timeout in seconds.
"""
command = self._get_nets_command(command)
_log.debug("Run command: %s", command)
# Note: we must not capture the stderr here (as with
# stderr=STDOUT), because otherwise successful 'ip netns exec <ns>
# <command> ...' call will write error messages to stderr if there are
# any bogus namespaces on the system. See
# https://github.com/projectcalico/libcalico/issues/148 for detailed
# discussion.
return check_output(command, timeout=IP_CMD_TIMEOUT)
示例13: version_for
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import check_output [as 别名]
def version_for(config):
"""
The version for an item is either the explicit version specified by
the user, or the SHA1 hash of hashable file.
"""
bits = []
if config.version_string:
bits.append(str(config.version_string))
if config.version_hashable:
log.debug("computing sha1 of: %s", config.version_hashable)
bits.append(file_sha1(config.version_hashable))
if config.version_command:
log.debug("version command: %s", config.version_command)
popenargs = shell_expand_to_popen(config.version_command, os.environ)
output = subprocess.check_output(
popenargs, stderr=SHELL_OUTPUT, stdin=DEV_NULL).strip()
if not configs._CONFIG_VERSION_RE.match(output):
raise configs.ConfigError(
"Invalid version output from version command: %r" % output)
bits.append(output)
return "-".join(bits)
#
# ---- Command line ----
示例14: _autodetect_zip_command
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import check_output [as 别名]
def _autodetect_zip_command():
try:
zip_output = subprocess.check_output(["zip", "-v"])
zip_cmd = "zip -q -r $ARCHIVE $DIR"
except subprocess.CalledProcessError as e:
raise ArchiveError("Archive handling requires 'zip' in path: %s" % e)
if zip_output.find("ZIP64_SUPPORT") < 0:
log.warn("installed 'zip' doesn't have Zip64 support so will fail for large archives")
log.debug("zip command: %s", zip_cmd)
return zip_cmd
示例15: subproc_call
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import check_output [as 别名]
def subproc_call(cmd, timeout=None):
try:
output = subprocess.check_output(
cmd, stderr=subprocess.STDOUT,
shell=True, timeout=timeout)
return output
except subprocess.TimeoutExpired as e:
logger.warn("Command timeout!")
logger.warn(e.output)
except subprocess.CalledProcessError as e:
logger.warn("Commnad failed: {}".format(e.returncode))
logger.warn(e.output)