本文整理汇总了Python中win32process.GetExitCodeProcess方法的典型用法代码示例。如果您正苦于以下问题:Python win32process.GetExitCodeProcess方法的具体用法?Python win32process.GetExitCodeProcess怎么用?Python win32process.GetExitCodeProcess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类win32process
的用法示例。
在下文中一共展示了win32process.GetExitCodeProcess方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: call
# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetExitCodeProcess [as 别名]
def call(self, method, args):
"""
Launch program to consume file
@type method: string
@param method: Command to execute
@type args: array of objects
@param args: Arguments to pass
"""
hProcess, hThread, dwProcessId, dwThreadId = win32process.CreateProcess(
None, self.commandLine, None, None, 0,
win32con.NORMAL_PRIORITY_CLASS, None, None, None)
while win32process.GetExitCodeProcess(hProcess) == win32con.STILL_ACTIVE:
time.sleep(0.25)
self.closeApp(hProcess, self._windowName)
示例2: exitCode
# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetExitCodeProcess [as 别名]
def exitCode(self):
"""
Return process exit code.
"""
return win32process.GetExitCodeProcess(self.hProcess)
示例3: join
# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetExitCodeProcess [as 别名]
def join(self):
win32event.WaitForSingleObject(self.processHandle,
win32event.INFINITE)
self.exitCode = win32process.GetExitCodeProcess(self.processHandle)
示例4: test_wait
# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetExitCodeProcess [as 别名]
def test_wait(self):
handle = win32api.OpenProcess(win32con.PROCESS_QUERY_INFORMATION,
win32con.FALSE, self.pid)
self.addCleanup(win32api.CloseHandle, handle)
p = psutil.Process(self.pid)
p.terminate()
psutil_value = p.wait()
sys_value = win32process.GetExitCodeProcess(handle)
self.assertEqual(psutil_value, sys_value)
示例5: checkWork
# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetExitCodeProcess [as 别名]
def checkWork(self):
if win32event.WaitForSingleObject(self.proc.hProcess, 0) != win32event.WAIT_OBJECT_0:
return 0
exitCode = win32process.GetExitCodeProcess(self.proc.hProcess)
self.deactivate()
self.proc.processEnded(exitCode)
return 0
示例6: close
# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetExitCodeProcess [as 别名]
def close(self):
if win32process.GetExitCodeProcess(self.handle) == win32con.STILL_ACTIVE:
self.kill()
self.child_stdin.close()
self.child_stdin = None
if self.child_stderr:
self.child_stdin.close()
self.child_stdin = None
es = ExitStatus(self.cmdline, self.child_stdout.close())
if self.exitstatus is None:
self.exitstatus = es
self.child_stdout = None
self.dead()
return self.exitstatus
示例7: poll
# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetExitCodeProcess [as 别名]
def poll(self):
es = win32process.GetExitCodeProcess(self.handle)
if es == win32con.STILL_ACTIVE:
return None
else:
self.exitstatus = ExitStatus(self.cmdline, es)
self.dead()
return self.exitstatus
# called when process determined to be daed
示例8: alive
# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetExitCodeProcess [as 别名]
def alive(self):
es = win32process.GetExitCodeProcess(self.handle)
if es == win32con.STILL_ACTIVE:
return True
else:
return False
# wait until finished
示例9: isalive
# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetExitCodeProcess [as 别名]
def isalive(self):
return win32process.GetExitCodeProcess(self.hProcess) == win32con.STILL_ACTIVE
示例10: _run_as_administrators
# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetExitCodeProcess [as 别名]
def _run_as_administrators(self, executable, arguments):
"""Invokes the specified executable with the specified arguments, escalating the privileges of the process
to Administrators.
All output that process generates to stdout/stderr will be echoed to this process's stdout/stderr.
Note, this can only be used on executables that accept the `--redirect-to-pipe` option to allow for this
process to capture the output from the escalated process.
Note, Windows will ask for confirmation and/or an Administrator password before the process is escalated.
@param executable: The path to the Windows executable to run escalated.
@param arguments: An array of arguments to supply to the executable.
@type executable: str
@type arguments: []
@return: The exit code of the process.
@rtype: int
"""
client = PipeRedirectorClient()
arguments = arguments + ["--redirect-to-pipe", client.pipe_name]
child_process = win32com.shell.shell.ShellExecuteEx(
fMask=256 + 64,
lpVerb="runas",
lpFile=executable,
lpParameters=" ".join(arguments),
)
client.start()
proc_handle = child_process["hProcess"]
win32event.WaitForSingleObject(proc_handle, -1)
client.stop()
return win32process.GetExitCodeProcess(proc_handle)
示例11: enumCallback
# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetExitCodeProcess [as 别名]
def enumCallback(hwnd, windowName):
"""
Will get called by win32gui.EnumWindows, once for each
top level application window.
"""
try:
# Get window title
title = win32gui.GetWindowText(hwnd)
# Is this our guy?
if title.find(windowName) == -1:
return
(threadId, processId) = win32process.GetWindowThreadProcessId(hwnd)
# Send WM_CLOSE message
try:
win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
win32gui.PostQuitMessage(hwnd)
except:
pass
# Give it upto 5 sec
for i in range(100):
if win32process.GetExitCodeProcess(processId) != win32con.STILL_ACTIVE:
# Process exited already
return
time.sleep(0.25)
try:
# Kill application
win32process.TerminateProcess(processId, 0)
except:
pass
except:
pass
示例12: checkWork
# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetExitCodeProcess [as 别名]
def checkWork(self):
if win32event.WaitForSingleObject(self.proc.hProcess, 0) != win32event.WAIT_OBJECT_0:
return 0
exitCode = win32process.GetExitCodeProcess(self.proc.hProcess)
if exitCode == 0:
err = error.ProcessDone(exitCode)
else:
err = error.ProcessTerminated(exitCode)
self.deactivate()
self.proc.protocol.processEnded(failure.Failure(err))
return 0
示例13: connectionLost
# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetExitCodeProcess [as 别名]
def connectionLost(self, reason=None):
"""Shut down resources."""
# Get the exit status and notify the protocol
exitCode = win32process.GetExitCodeProcess(self.hProcess)
if exitCode == 0:
err = error.ProcessDone(exitCode)
else:
err = error.ProcessTerminated(exitCode)
self.protocol.processEnded(failure.Failure(err))
## IConsumer
示例14: runAsAdmin
# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetExitCodeProcess [as 别名]
def runAsAdmin(cmdLine=None, wait=True):
if os.name != 'nt':
raise RuntimeError, "This function is only implemented on Windows."
import win32api
import win32con
import win32event
import win32process
from win32com.shell.shell import ShellExecuteEx
from win32com.shell import shellcon
python_exe = sys.executable
if cmdLine is None:
cmdLine = [python_exe] + sys.argv
elif type(cmdLine) not in (types.TupleType, types.ListType):
raise ValueError, "cmdLine is not a sequence."
cmd = '"%s"' % (cmdLine[0],)
# XXX TODO: isn't there a function or something we can call to massage command line params?
params = " ".join(['"%s"' % (x,) for x in cmdLine[1:]])
cmdDir = ''
#showCmd = win32con.SW_SHOWNORMAL
showCmd = win32con.SW_HIDE
lpVerb = 'runas' # causes UAC elevation prompt.
# print "Running", cmd, params
# ShellExecute() doesn't seem to allow us to fetch the PID or handle
# of the process, so we can't get anything useful from it. Therefore
# the more complex ShellExecuteEx() must be used.
# procHandle = win32api.ShellExecute(0, lpVerb, cmd, params, cmdDir, showCmd)
procInfo = ShellExecuteEx(nShow=showCmd,
fMask=shellcon.SEE_MASK_NOCLOSEPROCESS,
lpVerb=lpVerb,
lpFile=cmd,
lpParameters=params)
if wait:
procHandle = procInfo['hProcess']
obj = win32event.WaitForSingleObject(procHandle, win32event.INFINITE)
rc = win32process.GetExitCodeProcess(procHandle)
# print "Process handle %s returned code %s" % (procHandle, rc)
else:
rc = None
return rc
示例15: callWindows
# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetExitCodeProcess [as 别名]
def callWindows(self):
"""
Launch program to consume file
"""
# Launch via spawn
realArgs = ["cmd.exe", "/c", self.command]
for a in self.args:
realArgs.append(a)
phandle = os.spawnv(os.P_NOWAIT, os.path.join(os.getenv('SystemRoot'), 'system32', 'cmd.exe'), realArgs)
# Give it some time before we KILL!
for i in range(int(self.waitTime / 0.25)):
if win32process.GetExitCodeProcess(phandle) != win32con.STILL_ACTIVE:
# Process exited already
break
time.sleep(0.25)
try:
pid = ctypes.windll.kernel32.GetProcessId(ctypes.c_ulong(phandle))
if pid > 0:
for cid in self.FindChildrenOf(pid):
chandle = win32api.OpenProcess(1, 0, cid)
win32process.TerminateProcess(chandle, 0)
try:
win32api.CloseHandle(chandle)
except:
pass
win32process.TerminateProcess(phandle, 0)
try:
win32api.CloseHandle(phandle)
except:
pass
except:
pass