本文整理汇总了Python中os.popen3方法的典型用法代码示例。如果您正苦于以下问题:Python os.popen3方法的具体用法?Python os.popen3怎么用?Python os.popen3使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.popen3方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: popen3
# 需要导入模块: import os [as 别名]
# 或者: from os import popen3 [as 别名]
def popen3(cmd, mode="t", bufsize=-1):
"""Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd'
may be a sequence, in which case arguments will be passed directly to
the program without shell intervention (as with os.spawnv()). If 'cmd'
is a string it will be passed to the shell (as with os.system()). If
'bufsize' is specified, it sets the buffer size for the I/O pipes. The
file objects (child_stdin, child_stdout, child_stderr) are returned."""
import warnings
msg = "os.popen3 is deprecated. Use the subprocess module."
warnings.warn(msg, DeprecationWarning, stacklevel=2)
import subprocess
PIPE = subprocess.PIPE
p = subprocess.Popen(cmd, shell=isinstance(cmd, basestring),
bufsize=bufsize, stdin=PIPE, stdout=PIPE,
stderr=PIPE, close_fds=True)
return p.stdin, p.stdout, p.stderr
示例2: __call__
# 需要导入模块: import os [as 别名]
# 或者: from os import popen3 [as 别名]
def __call__(self):
try:
import subprocess
p = subprocess.Popen(self.argv,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
output, _ = p.communicate()
rc = p.returncode
except ImportError:
# py2.3?
fin, fout, ferr = os.popen3(" ".join(self.argv))
fin.close()
output = fout.read() + ferr.read()
fout.close()
rc = ferr.close()
if rc:
base = os.path.basename(self.argv[1])
# See if we can detect and reconstruct an exception in the output.
reconstituted = find_exception_in_output(output)
if reconstituted is not None:
raise reconstituted
raise AssertionError("%s failed with exit code %s. Output is:\n%s" % (base, rc, output))
示例3: wrap_popen3_for_win
# 需要导入模块: import os [as 别名]
# 或者: from os import popen3 [as 别名]
def wrap_popen3_for_win(cygwin_path):
"""Wrap popen3 to support #!-script on Windows.
Args:
cygwin_path: path for cygwin binary if command path is needed to be
translated. None if no translation required.
"""
__orig_popen3 = os.popen3
def __wrap_popen3(cmd, mode='t', bufsize=-1):
cmdline = cmd.split(' ')
interp = get_script_interp(cmdline[0], cygwin_path)
if interp:
cmd = interp + ' ' + cmd
return __orig_popen3(cmd, mode, bufsize)
os.popen3 = __wrap_popen3
示例4: run_command
# 需要导入模块: import os [as 别名]
# 或者: from os import popen3 [as 别名]
def run_command(self, command, check_output=True):
"""Run a command for this collectd plugin. Returns a tuple with command
success and output or False and None for output.
"""
output = None
try:
if check_output:
output = subprocess.check_output(command)
else:
stdin, stdout, stderr = os.popen3(' '.join(command))
output = stdout.read()
except Exception as exc:
collectd.error(
'collectd-ceph-storage: {} exception: {}'.format(command, exc))
collectd.error(
'collectd-ceph-storage: {} traceback: {}'
.format(command, traceback.format_exc()))
return False, None
if output is None:
collectd.error(
'collectd-ceph-storage: failed to {}: output is None'
.format(command))
return False, None
return True, output
示例5: start_local_analysis
# 需要导入模块: import os [as 别名]
# 或者: from os import popen3 [as 别名]
def start_local_analysis(file_path, cuckoo_path, kernel_analysis=False, timeout=300):
command = cuckoo_path+"/utils/submit.py "+file_path+" --timeout "+str(timeout)
if kernel_analysis != False:
command = command + " --options kernel_analysis=yes"
stdin,stdout,stderr = os.popen3(command)
is_task = 0
if stdout:
stdout_line = stdout.read()
if stderr:
stderr_line = stderr.read()
log.debug("Local command output STDOUT: "+stdout_line)
log.debug("Local command output STDERR: "+stderr_line)
if stdout_line != "":
id_task = int(stdout_line.split(" ")[-1])
else:
log.err("Local submit failed, stderr: "+stderr_line)
return id_task
示例6: log
# 需要导入模块: import os [as 别名]
# 或者: from os import popen3 [as 别名]
def log(self, rev_start=None, rev_end=1, verbose=False):
""" return a list of LogEntry instances for this path.
rev_start is the starting revision (defaulting to the first one).
rev_end is the last revision (defaulting to HEAD).
if verbose is True, then the LogEntry instances also know which files changed.
"""
assert self.check() # make it simpler for the pipe
rev_start = rev_start is None and "HEAD" or rev_start
rev_end = rev_end is None and "HEAD" or rev_end
if rev_start == "HEAD" and rev_end == 1:
rev_opt = ""
else:
rev_opt = "-r %s:%s" % (rev_start, rev_end)
verbose_opt = verbose and "-v" or ""
locale_env = fixlocale()
# some blather on stderr
auth_opt = self._makeauthoptions()
#stdin, stdout, stderr = os.popen3(locale_env +
# 'svn log --xml %s %s %s "%s"' % (
# rev_opt, verbose_opt, auth_opt,
# self.strpath))
cmd = locale_env + 'svn log --xml %s %s %s "%s"' % (
rev_opt, verbose_opt, auth_opt, self.strpath)
popen = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
)
stdout, stderr = popen.communicate()
stdout = py.builtin._totext(stdout, sys.getdefaultencoding())
minidom,ExpatError = importxml()
try:
tree = minidom.parseString(stdout)
except ExpatError:
raise ValueError('no such revision')
result = []
for logentry in filter(None, tree.firstChild.childNodes):
if logentry.nodeType == logentry.ELEMENT_NODE:
result.append(LogEntry(logentry))
return result
示例7: popen3
# 需要导入模块: import os [as 别名]
# 或者: from os import popen3 [as 别名]
def popen3(cmd, bufsize=-1, mode='t'):
"""Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may
be a sequence, in which case arguments will be passed directly to the
program without shell intervention (as with os.spawnv()). If 'cmd' is a
string it will be passed to the shell (as with os.system()). If
'bufsize' is specified, it sets the buffer size for the I/O pipes. The
file objects (child_stdout, child_stdin, child_stderr) are returned."""
w, r, e = os.popen3(cmd, mode, bufsize)
return r, w, e
示例8: threadPycheckerRun
# 需要导入模块: import os [as 别名]
# 或者: from os import popen3 [as 别名]
def threadPycheckerRun(self):
result=''
rc=-1
try:
options = self.greppattern
files= ' '.join(self.flist)
# Recently MarkH has failed to run pychecker without it having
# been explicitly installed - so we assume it is and locate it
# from its default location.
# Step1 - get python.exe
py = os.path.join(sys.prefix, 'python.exe')
if not os.path.isfile(py):
if "64 bit" in sys.version:
py = os.path.join(sys.prefix, 'PCBuild', 'amd64', 'python.exe')
else:
py = os.path.join(sys.prefix, 'PCBuild', 'python.exe')
try:
py = win32api.GetShortPathName(py)
except win32api.error:
py = ""
# Find checker.py
from distutils.sysconfig import get_python_lib
pychecker = os.path.join(get_python_lib(), 'pychecker', 'checker.py')
if not os.path.isfile(py):
result = "Can't find python.exe!\n"
elif not os.path.isfile(pychecker):
result = "Can't find checker.py - please install pychecker " \
"(or run 'setup.py install' if you have the source version)\n"
else:
cmd='%s "%s" %s %s 2>&1' % (py, pychecker, options,files)
##fin,fout,ferr=os.popen3(cmd)
##result=ferr.read()+fout.read()
result=os.popen(cmd).read()
##rc=f.close()
self.GetFirstView().Append(result)
finally:
self.result=result
print '== Pychecker run finished =='
self.GetFirstView().Append('\n'+'== Pychecker run finished ==')
self.SetModifiedFlag(0)
示例9: test_os_popen3
# 需要导入模块: import os [as 别名]
# 或者: from os import popen3 [as 别名]
def test_os_popen3(self):
# same test as test_popen3(), but using the os.popen*() API
if os.name == 'posix':
w, r, e = os.popen3([self.cmd])
self.validate_output(self.teststr, self.expected, r, w, e)
w, r, e = os.popen3(["echo", self.teststr])
got = r.read()
self.assertEqual(got, self.teststr + "\n")
got = e.read()
self.assertFalse(got, "unexpected %r on stderr" % got)
w, r, e = os.popen3(self.cmd)
self.validate_output(self.teststr, self.expected, r, w, e)
示例10: test_cp11334
# 需要导入模块: import os [as 别名]
# 或者: from os import popen3 [as 别名]
def test_cp11334(self):
#--Test that not using "# coding ..." results in a warning
t_in, t_out, t_err = os.popen3(sys.executable + " " + os.path.join(self.test_dir, "encoded_files", "cp11334_warn.py"))
t_err_lines = t_err.readlines()
t_out_lines = t_out.readlines()
t_err.close()
t_out.close()
t_in.close()
self.assertEqual(len(t_out_lines), 0)
self.assertTrue(t_err_lines[0].startswith(" File"))
self.assertTrue(t_err_lines[1].startswith("SyntaxError: Non-ASCII character '\\xb5' in file"))
#--Test that using "# coding ..." is OK
t_in, t_out, t_err = os.popen3(sys.executable + " " + os.path.join(self.test_dir, "encoded_files", "cp11334_ok.py"))
t_err_lines = t_err.readlines()
t_out_lines = t_out.readlines()
t_err.close()
t_out.close()
t_in.close()
self.assertEqual(len(t_err_lines), 0)
if not is_cli:
self.assertEqual(t_out_lines[0], "\xb5ble\n")
else:
print "CodePlex 11334"
self.assertEqual(t_out_lines[0], "\xe6ble\n")
self.assertEqual(len(t_out_lines), 1)
#TODO:@skip("multiple_execute")
示例11: test_cp1019
# 需要导入模块: import os [as 别名]
# 或者: from os import popen3 [as 别名]
def test_cp1019(self):
#--Test that bogus encodings fail properly
t_in, t_out, t_err = os.popen3(sys.executable + " " + os.path.join(self.test_dir, "encoded_files", "cp1019.py"))
t_err_lines = t_err.readlines()
t_out_lines = t_out.readlines()
t_err.close()
t_out.close()
t_in.close()
self.assertEqual(len(t_out_lines), 0)
self.assertTrue(t_err_lines[0].startswith(" File"))
self.assertTrue(t_err_lines[1].startswith("SyntaxError: encoding problem: with BOM"))