本文整理汇总了Python中System.Diagnostics.Process方法的典型用法代码示例。如果您正苦于以下问题:Python Diagnostics.Process方法的具体用法?Python Diagnostics.Process怎么用?Python Diagnostics.Process使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics
的用法示例。
在下文中一共展示了Diagnostics.Process方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from System import Diagnostics [as 别名]
# 或者: from System.Diagnostics import Process [as 别名]
def __init__(self, pathToBin, wkDir, *parms):
self.proc = Process()
self.proc.StartInfo.FileName = pathToBin
self.proc.StartInfo.WorkingDirectory = wkDir
self.proc.StartInfo.Arguments = " ".join(parms)
self.proc.StartInfo.UseShellExecute = False
self.proc.StartInfo.RedirectStandardOutput = True
self.proc.StartInfo.RedirectStandardInput = True
self.proc.StartInfo.RedirectStandardError = True
示例2: _demo_posix
# 需要导入模块: from System import Diagnostics [as 别名]
# 或者: from System.Diagnostics import Process [as 别名]
def _demo_posix():
#
# Example 1: Simple redirection: Get process list
#
plist = Popen(["ps"], stdout=PIPE).communicate()[0]
print "Process list:"
print plist
#
# Example 2: Change uid before executing child
#
if os.getuid() == 0:
p = Popen(["id"], preexec_fn=lambda: os.setuid(100))
p.wait()
#
# Example 3: Connecting several subprocesses
#
print "Looking for 'hda'..."
p1 = Popen(["dmesg"], stdout=PIPE)
p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE)
print repr(p2.communicate()[0])
#
# Example 4: Catch execution error
#
print
print "Trying a weird file..."
try:
print Popen(["/this/path/does/not/exist"]).communicate()
except OSError, e:
if e.errno == errno.ENOENT:
print "The file didn't exist. I thought so..."
print "Child traceback:"
print e.child_traceback
else:
print "Error", e.errno
示例3: generate
# 需要导入模块: from System import Diagnostics [as 别名]
# 或者: from System.Diagnostics import Process [as 别名]
def generate(exe, mod_name):
proc = Process()
proc.StartInfo.FileName = exe
proc.StartInfo.Arguments = "logmodule.py " + mod_name
proc.StartInfo.UseShellExecute = False
proc.StartInfo.RedirectStandardOutput = True
if not proc.Start():
raise Exception("process failed to start")
return proc.StandardOutput.ReadToEnd()
示例4: Popen
# 需要导入模块: from System import Diagnostics [as 别名]
# 或者: from System.Diagnostics import Process [as 别名]
def Popen(CMD, *a, **b):
'''
CMD is a list - a command and its arguments
'''
p = Process()
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardInput = True
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.RedirectStandardError = True
p.StartInfo.FileName = CMD[0]
p.StartInfo.Arguments = ' '.join(CMD[1:])
p.Start()
return(p)
示例5: _execute_child
# 需要导入模块: from System import Diagnostics [as 别名]
# 或者: from System.Diagnostics import Process [as 别名]
def _execute_child(self, args, executable, preexec_fn, close_fds,
cwd, env, universal_newlines,
startupinfo, creationflags, shell, to_close,
p2cread, p2cwrite,
c2pread, c2pwrite,
errread, errwrite):
"""Execute program (MS Windows version)"""
if not isinstance(args, types.StringTypes):
args = list2cmdline(args)
# Process startup details
if startupinfo is None:
startupinfo = STARTUPINFO()
if None not in (p2cread, c2pwrite, errwrite):
startupinfo.dwFlags |= _subprocess.STARTF_USESTDHANDLES
startupinfo.hStdInput = p2cread
startupinfo.hStdOutput = c2pwrite
startupinfo.hStdError = errwrite
if shell:
startupinfo.dwFlags |= _subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = _subprocess.SW_HIDE
comspec = os.environ.get("COMSPEC", "cmd.exe")
args = '{} /c "{}"'.format (comspec, args)
if (_subprocess.GetVersion() >= 0x80000000 or
os.path.basename(comspec).lower() == "command.com"):
# Win9x, or using command.com on NT. We need to
# use the w9xpopen intermediate program. For more
# information, see KB Q150956
# (http://web.archive.org/web/20011105084002/http://support.microsoft.com/support/kb/articles/Q150/9/56.asp)
w9xpopen = self._find_w9xpopen()
args = '"%s" %s' % (w9xpopen, args)
# Not passing CREATE_NEW_CONSOLE has been known to
# cause random failures on win9x. Specifically a
# dialog: "Your program accessed mem currently in
# use at xxx" and a hopeful warning about the
# stability of your system. Cost is Ctrl+C wont
# kill children.
creationflags |= _subprocess.CREATE_NEW_CONSOLE
def _close_in_parent(fd):
fd.Close()
to_close.remove(fd)
# Start the process
try:
hp, ht, pid, tid = _subprocess.CreateProcess(executable, args,
# no special security
None, None,
int(not close_fds),
creationflags,
env,
cwd,
startupinfo)
except pywintypes.error, e:
# Translate pywintypes.error to WindowsError, which is
# a subclass of OSError. FIXME: We should really
# translate errno using _sys_errlist (or similar), but
# how can this be done from Python?
raise WindowsError(*e.args)