<DIV>Gracias, es verdad que estaba cambiado de orden los parametros al crear el proceso, pero el que tengo que utilizar es el manejador del proceso y no el del hilo.</DIV>
<DIV> </DIV>
<DIV>Ahora el problema que me da es que no tengo acceso a la tuberia, como si estuviera bloqueada por el proceso y no me dejara leer mientras esta escribiendo. La excepcion es la siguiente:</DIV>
<DIV> </DIV>
<DIV>Traceback (most recent call last):<BR> File "pruebaWin32Process3.py", line 54, in ?<BR>pywintypes.api_error: (5, 'GetNamedPipeHandleState', 'Acceso denegado.')</DIV>
<DIV> </DIV>
<DIV>Te vuelvo a mandar el codigo por si te sirve de ayuda.</DIV>
<DIV> </DIV>
<DIV>import win32process<BR>import win32pipe<BR>import win32api<BR>import win32con<BR>import win32security<BR>import os,time</DIV>
<DIV>if __name__ == "__main__":<BR> cmdline="D:\\Programa.exe"<BR> """Creates a new process which uses the specified handles for its standard<BR> input, output, and error. The handles must be inheritable. 0 can be passed<BR> as a special handle indicating that the process should inherit the current<BR> process's input, output, or error streams, and None can be passed to discard<BR> the child process's output or to prevent it from reading any input."""</DIV>
<DIV> # initialize new process's startup info<BR> sAttrs=win32security.SECURITY_ATTRIBUTES()<BR> hPipeIn, hPipeOut=win32pipe.CreatePipe(sAttrs, 0)</DIV>
<DIV> si = win32process.STARTUPINFO()<BR> si.dwFlags = win32process.STARTF_USESTDHANDLES</DIV>
<DIV> si.hStdInput=hPipeIn<BR> si.hStdOutput=hPipeOut</DIV>
<DIV> # create the process<BR> processhandle, threadhandle,pid, tid = win32process.CreateProcess \<BR> ( None, # appName<BR> cmdline, # commandLine<BR> None, # processAttributes<BR> None, #
threadAttributes<BR> 1, # bInheritHandles<BR> win32con.NORMAL_PRIORITY_CLASS, # dwCreationFlags<BR> None, # newEnvironment<BR> None, # currentDirectory<BR>
si # startupinfo<BR> )</DIV>
<DIV> print 'voy a entrar al bucle'<BR> contador=2 #contador de espera<BR> while 1:<BR> print 'iteracion '+str(win32process.GetExitCodeProcess(processhandle))<BR> if (win32process.GetExitCodeProcess(processhandle) >=1):#codigo del proceso<BR> if contador==0:<BR> print 'Termino el proceso'<BR> win32api.TerminateProcess(processhandle,-1)<BR> break<BR> buffer, bytesToRead, ignore = win32pipe.PeekNamedPipe(hPipeOut,
0)<BR> print 'valor salida '+str(buffer)<BR> contador=contador-1<BR> time.sleep(10)<BR> else:<BR> print 'salgo del bucle'<BR> break <BR><BR><B><I>Chema_Cortés <ch3m4@ch3m4.org></I></B> wrote:</DIV>
<BLOCKQUOTE class=replbq style="BORDER-LEFT: #1010ff 2px solid; MARGIN-LEFT: 5px; PADDING-LEFT: 5px">Gema Núñez Blázquez escribió:<BR>> Perdonad por ser tan pesada con el temita pero es que no me termina de <BR>> salir. Siguiendo tu consejo he utilizado win32process y win32pipe, y <BR>> consigo que el proceso se ejecute y me de el manejador para poder <BR>> preguntar si sigue vivo. Mi problema es que no soy capaz de leer la <BR>> tuberia de salida ni de error:<BR>> <BR>> buffer, bytesToRead, ignore = <BR>> win32pipe.PeekNamedPipe(si.hStdOutput, 0)<BR>> print 'valor salida '+str(buffer)<BR>> <BR>> porque me da el siguiente error:<BR>> Traceback (most recent call last):<BR>> File "pruebaWin32Process3.py", line 47, in ?<BR>> pywintypes.api_error: (6, 'GetNamedPipeHandleState', 'Controlador no <BR>> v\xe1lido.'<BR>> )<BR>> <BR>> se supone que el manejador del pipe está en si.hStdOutput, ¿no?<BR><BR>Pues yo diría que no, ya que
en
realidad no has creado ningún pipe. Al <BR>crear el proceso, en lugar de conectarlo a las entradas/salidas del <BR>proceso padre deberías conectarlo a un pipe para procesarlas:<BR><BR>sAttrs=win32security.SECURITY_ATTRIBUTES()<BR>hPipeIn, hPipeOut = win32pipe.CreatePipe(sAttrs, 0)<BR><BR>...<BR>si.hStdOutput = hPipeOut<BR><BR><BR>Así mismo, creo que tiene un error en<BR><BR>> # create the process<BR>> phandle, pid, thandle, tid = win32process.CreateProcess \<BR><BR>está mal el orden. Sería (phandle, thandle, pid, tid), siendo thandle el <BR>handle del proceso hijo, no phandle como parace que estás usando.<BR><BR><BR><BR>-- <BR>Res publica non dominetur<BR><BR><BR>_______________________________________________<BR>Python-es mailing list<BR>Python-es@aditel.org<BR>http://listas.aditel.org/listinfo/python-es</BLOCKQUOTE><p><hr size=1><font face="Arial" size="-1" color="#FF8000"><b>Yahoo! Messenger</b></font><br><font face="Arial" size="-1" color="black"><a
href=http://es.rd.yahoo.com/mail_es/tagline/messenger/*http://es.messenger.yahoo.com/><b>Nueva versión</b></a>: Super Webcam, voz, caritas animadas, y más ¡Gratis!</font>