Ticket #5726: dont-open-console-window.diff

File dont-open-console-window.diff, 2.4 KB (added by alecu, 4 years ago)

Use the CREATE_NO_WINDOW flag to call CreateProcess

  • twisted/internet/_dumbwin32proc.py

    === modified file 'twisted/internet/_dumbwin32proc.py'
     
    172172        cmdline = quoteArguments(args)
    173173        # TODO: error detection here.  See #2787 and #4184.
    174174        def doCreate():
     175            flags = win32con.CREATE_NO_WINDOW
    175176            self.hProcess, self.hThread, self.pid, dwTid = win32process.CreateProcess(
    176                 command, cmdline, None, None, 1, 0, env, path, StartupInfo)
     177                command, cmdline, None, None, 1, flags, env, path, StartupInfo)
    177178        try:
    178179            try:
    179180                doCreate()
  • twisted/test/test_process.py

    === modified file 'twisted/test/test_process.py'
     
    22712271
    22722272
    22732273
     2274class Win32CreateProcessFlagsTest(unittest.TestCase):
     2275    """
     2276    Check the flags passed to CreateProcess.
     2277    """
     2278
     2279    @defer.inlineCallbacks
     2280    def test_flags(self):
     2281        """
     2282        Verify the flags passed to win32process.CreateProcess().
     2283        """
     2284        from twisted.internet import _dumbwin32proc
     2285        flags = []
     2286        real_CreateProcess = _dumbwin32proc.win32process.CreateProcess
     2287
     2288        def fake_createprocess(*args):
     2289            """Store the args for later comparing."""
     2290            flags.append(args)
     2291            return real_CreateProcess(*args)
     2292
     2293        self.patch(_dumbwin32proc.win32process, "CreateProcess",
     2294                   fake_createprocess)
     2295        exe = sys.executable
     2296        scriptPath = util.sibpath(__file__, "process_cmdline.py")
     2297
     2298        d = defer.Deferred()
     2299        processProto = TrivialProcessProtocol(d)
     2300        comspec = str(os.environ["COMSPEC"])
     2301        cmd = [comspec, "/c", exe, scriptPath]
     2302        _dumbwin32proc.Process(reactor, processProto, None, cmd, {}, None)
     2303        yield d
     2304        self.assertEqual(flags[0][5],
     2305                         _dumbwin32proc.win32process.CREATE_NO_WINDOW)
     2306
     2307
     2308
    22742309class UtilTestCase(unittest.TestCase):
    22752310    """
    22762311    Tests for process-related helper functions (currently only
     
    24742509    Win32ProcessTestCase.skip = skipMessage
    24752510    TestTwoProcessesNonPosix.skip = skipMessage
    24762511    Dumbwin32procPidTest.skip = skipMessage
     2512    Win32CreateProcessFlagsTest.skip = skipMessage
    24772513    Win32UnicodeEnvironmentTest.skip = skipMessage
    24782514
    24792515if not interfaces.IReactorProcess(reactor, None):