本文整理匯總了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