Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python:在windows中使用createprocessasuser api时处理stderr流_Python_Windows_Createprocessasuser - Fatal编程技术网

python:在windows中使用createprocessasuser api时处理stderr流

python:在windows中使用createprocessasuser api时处理stderr流,python,windows,createprocessasuser,Python,Windows,Createprocessasuser,需要一些调试此问题的帮助。我尝试在线搜索和stackoverflow,但找不到解决方案。我对windows api相当陌生,请原谅我的无知 基本上,我正在尝试运行一个C++应用程序,它使用特定的用户从Python输出到STDUT和STDRR。为此,我使用LogonUser API和CreateProcessAsUser API调用二进制文件,并使用管道捕获输出和错误流。我们主要从python win32模块中的演示代码中获取了这些代码。然而,由于某种原因,当我的进程转储到错误流时,它会挂起在Wr

需要一些调试此问题的帮助。我尝试在线搜索和stackoverflow,但找不到解决方案。我对windows api相当陌生,请原谅我的无知

<>基本上,我正在尝试运行一个C++应用程序,它使用特定的用户从Python输出到STDUT和STDRR。为此,我使用LogonUser API和CreateProcessAsUser API调用二进制文件,并使用管道捕获输出和错误流。我们主要从python win32模块中的演示代码中获取了这些代码。然而,由于某种原因,当我的进程转储到错误流时,它会挂起在WriteFile。查看崩溃转储,我看到文件句柄是2(stderr)。有人能帮我解决这个问题吗

提前谢谢

下面是代码片段--

userToken = win32security.LogonUser(user, domain, password,
                                    win32con.LOGON32_LOGON_BATCH,
                                    win32con.LOGON32_PROVIDER_DEFAULT)

secAttrs = win32security.SECURITY_ATTRIBUTES()
secAttrs.bInheritHandle = 1
stdout_r, stdout_w = win32pipe.CreatePipe(secAttrs, 0)
stderr_r, stderr_w = win32pipe.CreatePipe(secAttrs, 0)

startupInfo = win32process.STARTUPINFO()
startupInfo.dwFlags = win32con.STARTF_USESTDHANDLES
startupInfo.hStdOutput = stdout_w
startupInfo.hStdError = stderr_w

ppid = win32api.GetCurrentProcess()
tmp = win32api.DuplicateHandle(ppid, stdout_r, ppid, 0, 0,
                               win32con.DUPLICATE_SAME_ACCESS)
win32file.CloseHandle(stdout_r)
stdout_r = tmp

procArgs = (None,       # appName
            cmd_line,   # commandLine
            None,       # processAttributes
            None,       # threadAttributes
            1,          # bInheritHandles
            win32process.CREATE_NEW_CONSOLE, # dwCreationFlags
            None,       # newEnvironment
            None,       # currentDirectory
            startupInfo)

procHandles = win32process.CreateProcessAsUser(userToken, *procArgs)

win32file.CloseHandle(stderr_w)
win32file.CloseHandle(stdout_w)
win32security.RevertToSelf()

# Wait for process to complete
hProcess, hThread, pid, tid = procHandles

stdout_buf = os.fdopen(msvcrt.open_osfhandle(stdout_r, 0), "rb")
stdout = stdout_buf.read()
stderr_buf = os.fdopen(msvcrt.open_osfhandle(stderr_r, 0), "rb")
stderr = stderr_buf.read()

win32event.WaitForSingleObject(hProcess, 3600*1000)
rc = win32process.GetExitCodeProcess(hProcess)