[pywin32-checkins] pywin32/win32/Demos winprocess.py,1.3,1.4
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
|
From: Mark H. <mha...@us...> - 2009-01-14 13:04:35
|
Update of /cvsroot/pywin32/pywin32/win32/Demos In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv3275/win32/Demos Modified Files: winprocess.py Log Message: bash demo back into shape and working with py2k and py3k Index: winprocess.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/Demos/winprocess.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** winprocess.py 1 Oct 2008 14:44:53 -0000 1.3 --- winprocess.py 14 Jan 2009 12:12:26 -0000 1.4 *************** *** 17,20 **** --- 17,21 ---- import win32api, win32process, win32security import win32event, win32con, msvcrt, win32gui + import os *************** *** 178,182 **** cmdString = """\ REM Test of winprocess.py piping commands to a shell.\r ! REM This window will close in %d seconds.\r vol\r net user\r --- 179,183 ---- cmdString = """\ REM Test of winprocess.py piping commands to a shell.\r ! REM This 'notepad' process will terminate in %d seconds.\r vol\r net user\r *************** *** 184,195 **** """ % timeoutSeconds ! cmd, out = tempfile.TemporaryFile(), tempfile.TemporaryFile() ! cmd.write(cmdString) ! cmd.seek(0) ! print 'CMD.EXE exit code:', run('cmd.exe', show=0, stdin=cmd, ! stdout=out, stderr=out) ! cmd.close() ! print 'NOTEPAD exit code:', run('notepad.exe %s' % out.file.name, ! show=win32con.SW_MAXIMIZE, ! mSec=timeoutSeconds*1000) ! out.close() --- 185,206 ---- """ % timeoutSeconds ! cmd_name = tempfile.mktemp() ! out_name = cmd_name + '.txt' ! try: ! cmd = open(cmd_name, "w+b") ! out = open(out_name, "w+b") ! cmd.write(cmdString.encode('mbcs')) ! cmd.seek(0) ! print 'CMD.EXE exit code:', run('cmd.exe', show=0, stdin=cmd, ! stdout=out, stderr=out) ! cmd.close() ! print 'NOTEPAD exit code:', run('notepad.exe %s' % out.name, ! show=win32con.SW_MAXIMIZE, ! mSec=timeoutSeconds*1000) ! out.close() ! finally: ! for n in (cmd_name, out_name): ! try: ! os.unlink(cmd_name) ! except os.error: ! pass |