本文整理汇总了Python中os.popen4方法的典型用法代码示例。如果您正苦于以下问题:Python os.popen4方法的具体用法?Python os.popen4怎么用?Python os.popen4使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.popen4方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: popen4
# 需要导入模块: import os [as 别名]
# 或者: from os import popen4 [as 别名]
def popen4(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_stderr) are returned."""
import warnings
msg = "os.popen4 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=subprocess.STDOUT, close_fds=True)
return p.stdin, p.stdout
示例2: shell
# 需要导入模块: import os [as 别名]
# 或者: from os import popen4 [as 别名]
def shell(self, cmd,verbose=0,debug=0,header=''):
'''
Replacement method to allow shell commands without them blocking.
@param cmd: Shell command to execute.
@type cmd: string
@param verbose: Verbosity
@type verbose: integer
@param debug: Debug level
@type debug: integer
@param header: Header to be printed before output
@type header: string
'''
stat = 0
if verbose or debug: print header+cmd
# flush stdout so we don't mangle python's buffering
if not debug:
input, output = os.popen4(cmd)
print output.read()
output.close()
input.close()
示例3: shell
# 需要导入模块: import os [as 别名]
# 或者: from os import popen4 [as 别名]
def shell(self, cmd,verbose=0,debug=0,header=''):
"""!
Replacement method to allow shell commands without them blocking.
@param cmd: Shell command to execute.
@param verbose: Verbosity
@param debug: Debug level
@param header: Header to be printed before output
@return none
"""
stat = 0
if verbose or debug: print header+cmd
# flush stdout so we don't mangle python's buffering
if not debug:
input, output = os.popen4(cmd)
print output.read()
output.close()
input.close()
## ConsoleView class
示例4: popen
# 需要导入模块: import os [as 别名]
# 或者: from os import popen4 [as 别名]
def popen(fullcmd):
pipein, pipeout = os.popen4(fullcmd)
return pipeout
示例5: read_process
# 需要导入模块: import os [as 别名]
# 或者: from os import popen4 [as 别名]
def read_process(cmd, args=''):
pipein, pipeout = os.popen4('%s %s' % (cmd, args))
try:
firstline = pipeout.readline()
if (re.search(r'(not recognized|No such file|not found)', firstline,
re.IGNORECASE)):
raise IOError('%s must be on your system path.' % cmd)
output = firstline + pipeout.read()
finally:
pipeout.close()
return output
示例6: popen4
# 需要导入模块: import os [as 别名]
# 或者: from os import popen4 [as 别名]
def popen4(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_stderr, child_stdin) are returned."""
w, r = os.popen4(cmd, mode, bufsize)
return r, w