本文整理汇总了Python中subprocess.Popen.close方法的典型用法代码示例。如果您正苦于以下问题:Python Popen.close方法的具体用法?Python Popen.close怎么用?Python Popen.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类subprocess.Popen
的用法示例。
在下文中一共展示了Popen.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import close [as 别名]
def main(argv):
run_in_reverse = False
if len(argv) > 1:
if argv[1] == '--help' or argv[1] == '-h':
print ('Usage: %s [<commit>]' % argv[0])
print ('\tdiff to framework, ' +
'optionally restricting to files in <commit>')
sys.exit(0)
elif argv[1] == '--reverse':
print "Running in reverse"
run_in_reverse = True
else:
print ("**** Pulling file list from: %s" % argv[1])
pipe = Popen(['git', 'diff', '--name-only', argv[1]], stdout=PIPE).stdout
for line in iter(pipe.readline,''):
path = line.rstrip()
file = path[path.rfind('/') + 1:]
print '**** watching: %s' % file
WATCH.append(file);
pipe.close()
if run_in_reverse:
#dirCompare(FW_RES, PROTO_RES, ".xml", run_in_reverse)
print ("**** Source files:")
dirCompare(FW_SRC, PROTO_SRC, ".java", run_in_reverse)
else:
#dirCompare(PROTO_RES, FW_RES, ".xml", run_in_reverse)
print ("**** Source files:")
dirCompare(PROTO_SRC, FW_SRC, ".java", run_in_reverse)
if (os.path.exists(TEMP_FILE1)):
os.remove(TEMP_FILE1)
if (os.path.exists(TEMP_FILE2)):
os.remove(TEMP_FILE2)
示例2: _hostIsUp
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import close [as 别名]
def _hostIsUp(host, count=1, timeout=1):
"""
Executes a ping command and sets the appropriate attribute.
Parameters: A host, optional: Amount of pings, Timeout
"""
thecommand = 'ping -n {0} -w {1} -a {2}'.format(count, timeout, host.ipaddress)
results = Popen(thecommand, stdout=PIPE).stdout
output = results.readlines()
results.close()
# Convert the returned bytearrays to strings.
output = [item.decode('utf8') for item in output]
output = ' '.join(output)
if ('Request timed out' in output) or ('Destination net unreachable' in output):
if host.isup == True:
host.isup = False
host.changed = True
else:
if host.isup == False:
host.isup = True
host.changed = True
示例3: __init__
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import close [as 别名]
def __init__(self, setupsDir=DEFAULT_SETUPS_DIR):
# initial setup of ups itself:
os.environ['UPS_SHELL'] = 'sh'
# initial setup of ups itself:
os.environ['UPS_SHELL'] = 'sh'
if POPEN_AVAILABLE:
f = Popen('. %s/setups.sh; ' % setupsDir + \
'echo os.environ\\[\\"UPS_DIR\\"\\]=\\"${UPS_DIR}\\"; ' + \
'echo os.environ\\[\\"PRODUCTS\\"\\]=\\"${PRODUCTS}\\";' + \
'echo os.environ\\[\\"SETUP_UPS\\"\\]=\\"${SETUP_UPS}\\";' + \
'echo os.environ\\[\\"PYTHONPATH\\"\\]=\\"${PYTHONPATH}\\";',
shell=True,
stdout=PIPE).stdout
else:
f = os.popen('. %s/setups.sh; ' % setupsDir + \
'echo os.environ\\[\\"UPS_DIR\\"\\]=\\"${UPS_DIR}\\"; ' + \
'echo os.environ\\[\\"PRODUCTS\\"\\]=\\"${PRODUCTS}\\";' + \
'echo os.environ\\[\\"SETUP_UPS\\"\\]=\\"${SETUP_UPS}\\";' + \
'echo os.environ\\[\\"PYTHONPATH\\"\\]=\\"${PYTHONPATH}\\";')
exec f.read()
f.close()
# we need to initialize the following so that we can
# make the correct changes to sys.path later when products
# we setup modify PYTHONPATH
self._pythonPath = os.environ.get('PYTHONPATH', '')
self._sysPath = sys.path
(self._internalSysPathPrepend, self._internalSysPathAppend) = self._getInitialSyspathElements()
示例4: _inhaleresults
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import close [as 别名]
def _inhaleresults(self, cmd):
if POPEN_AVAILABLE:
p = Popen(cmd, shell=True,
stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
(stdin, stdout, stderr) = (p.stdin, p.stdout, p.stderr)
else:
(stdin,stdout,stderr) = os.popen3(cmd)
try:
filename = stdout.read()
filename = filename[0:-1]
if (filename == "/dev/null"):
msg = stderr.read()
raise upsException(msg)
finally:
stdin.close()
stdout.close()
stderr.close()
cutHere = '--------------cut here-------------'
setup = open(filename, 'a')
setup.write(self._getNewPythonEnv(cutHere))
setup.close()
if POPEN_AVAILABLE:
f = Popen("/bin/sh %s" % filename,
shell=True, stdout=PIPE).stdout
else:
f = os.popen("/bin/sh %s" % filename)
c1 = f.read()
f.close()
(realUpsStuff, ourOsEnvironmentStuff) = re.split('.*%s' % cutHere, c1)
#print("ourOsEnvironmentStuff = %s" % ourOsEnvironmentStuff)
exec ourOsEnvironmentStuff
示例5: _get_fields
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import close [as 别名]
def _get_fields(self, msg_path, length=50):
cmd = [
'mu',
'view',
msg_path,
'--summary-len=5',
'--muhome=%s' % config.HIPFLASK_FOLDERS['mu']
]
p = Popen(cmd, stdout=PIPE).stdout
fields = p.read().splitlines()
p.close()
message = {}
for field in fields:
separator = field.find(':')
if separator == -1:
continue
key = field[0:separator].lower()
value = field[separator+2:]
if len(value) > length:
value = value[:length] + '...'
message[key] = value
return message
示例6: copy_text
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import close [as 别名]
def copy_text(text):
cb_name = get_clipboard_name()
if cb_name is not None:
clipboard = Popen(cb_name, shell=True, stdin=PIPE).stdin
clipboard.write(text)
clipboard.close()
示例7: executeCommandAndArguments
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import close [as 别名]
def executeCommandAndArguments(caa, dumpfilepath):
result = Popen(caa, stdout=PIPE).stdout
dumpfile = open(dumpfilepath, 'w')
dumpfile.write( result.read() )
dumpfile.close()
result.close()
示例8: mavchildexec
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import close [as 别名]
class mavchildexec(mavfile):
'''a MAVLink child processes reader/writer'''
def __init__(self, filename, source_system=255):
from subprocess import Popen, PIPE
import fcntl
self.filename = filename
self.child = Popen(filename, shell=True, stdout=PIPE, stdin=PIPE)
self.fd = self.child.stdout.fileno()
fl = fcntl.fcntl(self.fd, fcntl.F_GETFL)
fcntl.fcntl(self.fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
fl = fcntl.fcntl(self.child.stdout.fileno(), fcntl.F_GETFL)
fcntl.fcntl(self.child.stdout.fileno(), fcntl.F_SETFL, fl | os.O_NONBLOCK)
mavfile.__init__(self, self.fd, filename, source_system=source_system)
def close(self):
self.child.close()
def recv(self,n=None):
try:
x = self.child.stdout.read(1)
except Exception:
return ''
return x
def write(self, buf):
self.child.stdin.write(buf)
示例9: run_repair
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import close [as 别名]
def run_repair(n, k, d, w, helper_ids, failed_id):
htime = ftime = 0.0
print "running repair [HELP]..."
cmd1 = "./repair_pmc help %d %s %s" % (failed_id, mfname, " ".join(map(str, helper_ids)))
print cmd1
stdout = Popen(cmd1, shell=True, stdout=PIPE, stderr=sys.stderr).stdout
for line in stdout:
if VERBOSE:
sys.stdout.write(line) # echo output
if 'Coding Time' in line:
htime += float(line.split(':')[1].strip())
stdout.close()
print "running repair [FIX]..."
cmd2 = "./repair_pmc fix %d %s %s" % (failed_id, mfname, " ".join(map(str, helper_ids)))
print cmd2
stdout = Popen(cmd2, shell=True, stdout=PIPE, stderr=sys.stderr).stdout
for line in stdout:
if VERBOSE:
sys.stdout.write(line) # echo output
if 'Coding Time' in line:
ftime += float(line.split(':')[1].strip())
return htime, ftime
示例10: __init__
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import close [as 别名]
class LineReader:
def __init__(self, fname):
if fname.endswith(".gz"):
if not os.path.isfile(fname):
raise IOError(fname)
self.f = Popen(["gunzip", "-c", fname], stdout=PIPE, stderr=PIPE)
self.zipped = True
else:
self.f = open(fname, "r")
self.zipped = False
def readlines(self):
if self.zipped:
for line in self.f.stdout:
yield line
else:
for line in self.f.readlines():
yield line
def close(self):
if self.zipped:
if self.f.poll() == None:
os.kill(self.f.pid, signal.SIGHUP)
else:
self.f.close()
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
self.close()
def __iter__(self):
return self.readlines()
示例11: determineDependancies
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import close [as 别名]
def determineDependancies(self, app):
otoolPipe = Popen('otool -L "%s"' % app, shell=True, stdout=PIPE).stdout
otoolOutput = [line for line in otoolPipe]
otoolPipe.close()
libs = [line.split()[0] for line in otoolOutput[1:] if "Qt" in line and not "@executable_path" in line]
frameworks = [lib[:lib.find(".framework")+len(".framework")] for lib in libs]
return zip(frameworks, libs)
示例12: create_user
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import close [as 别名]
def create_user(username):
print "Checking for user "+username
p = Popen('id '+username, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
output = p.stdout.read()
if (output[0:3] != "uid"):
# Make the pypo user
print "Creating user "+username
os.system("adduser --system --quiet --group --shell /bin/bash "+username)
#set pypo password
p = os.popen('/usr/bin/passwd pypo 1>/dev/null 2>&1', 'w')
p.write('pypo\n')
p.write('pypo\n')
p.close()
else:
print "User already exists."
#add pypo to audio group
os.system("adduser " + username + " audio 1>/dev/null 2>&1")
#add pypo to www-data group
os.system("adduser " + username + " www-data 1>/dev/null 2>&1")
#add pypo to pulse group
os.system("adduser " + username + " pulse 1>/dev/null 2>&1")
#add pypo to pulse-access group
os.system("adduser " + username + " pulse-access 1>/dev/null 2>&1")
示例13: git_version
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import close [as 别名]
def git_version(path):
from subprocess import Popen, PIPE, STDOUT
cmd = 'git --git-dir=' + path + '.git log --pretty=format:%h -n1'
p = Popen(cmd, shell=True, stdout=PIPE).stdout
version = p.read()
p.close()
return version
示例14: get_surface
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import close [as 别名]
def get_surface( lemma_morph, pos ) :
"""
Given a lemma+morph in RASP format, returns a tuple containing (surface,
lemma). Uses morphg to generate the surface, or returns 2 copies of
the input if morphg was not provided.
"""
global morphg_file
parts = lemma_morph.rsplit("+",1)
if len(parts) == 1 or lemma_morph == "+": # No inflection
lemma = surface = lemma_morph
elif len(parts) == 2 and "+" not in parts[0]: # Standard inflected unit
lemma = parts[0]
if morphg_file is not None :
lemma_morph = lemma_morph.replace("\"","\\\"")
cmd = "echo \"%s_%s\" | ${morphg_res:-./%s -t}" % \
( lemma_morph, pos, morphg_file )
p = Popen(cmd, shell=True, stdout=PIPE).stdout
#generates the surface form using morphg
surface = unicode(p.readline(), 'utf-8').split("_")[ 0 ]
p.close()
else:
surface = lemma
else: # the token contains one or several '+'
lemma = surface = parts[0]
return ( surface, lemma )
示例15: run
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import close [as 别名]
def run(self, edit):
selections = self.view.sel()
# For now we don't try to balance multiple or non-empty selections, just insert as usual
if len(selections) > 1:
for selection in reversed(selections):
self.insert(edit, selection)
return
selection = selections[0]
if not selection.empty():
self.insert(edit, selection)
return
point = selection.end()
line = self.view.line(point)
os.environ["TM_CURRENT_LINE"] = self.view.substr(line).encode("utf-8")
os.environ["TM_LINE_INDEX"] = unicode(self.view.rowcol(point)[1])
os.environ["TM_SUPPORT_PATH"] = os.getcwd().encode("utf-8")
pipe = Popen(["ruby", os.path.join(self.package_path(), self.PARSER_PATH)], shell=False, stdout=PIPE, stderr=STDOUT).stdout
snippet = pipe.read()
pipe.close()
self.view.erase(edit, line)
self.view.run_command("insert_snippet", {"contents": unicode(snippet, "utf-8")})