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

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

Fixes issues requested on the first review

  • 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'
     
    2727from twisted.python.log import msg
    2828from twisted.internet import reactor, protocol, error, interfaces, defer
    2929from twisted.trial import unittest
    30 from twisted.python import util, runtime, procutils
     30from twisted.python import filepath, util, runtime, procutils
    3131from twisted.python.compat import set
    3232
    3333
     
    23502350
    23512351
    23522352
     2353class Win32CreateProcessFlagsTest(unittest.TestCase):
     2354    """
     2355    Check the flags passed to CreateProcess.
     2356    """
     2357
     2358    @defer.inlineCallbacks
     2359    def test_flags(self):
     2360        """
     2361        Verify that the flags passed to win32process.CreateProcess() prevent a
     2362        new console window from being created. See bug #5726 for a script to
     2363        test this interactively.
     2364        """
     2365        from twisted.internet import _dumbwin32proc
     2366        flags = []
     2367        real_CreateProcess = _dumbwin32proc.win32process.CreateProcess
     2368
     2369        def fake_createprocess(_appName, _commandLine, _processAttributes,
     2370                            _threadAttributes, _bInheritHandles, creationFlags,
     2371                            _newEnvironment, _currentDirectory, startupinfo):
     2372            """Store the creationFlags for later comparing."""
     2373            flags.append(creationFlags)
     2374            return real_CreateProcess(_appName, _commandLine,
     2375                            _processAttributes, _threadAttributes,
     2376                            _bInheritHandles, creationFlags, _newEnvironment,
     2377                            _currentDirectory, startupinfo)
     2378
     2379        self.patch(_dumbwin32proc.win32process, "CreateProcess",
     2380                   fake_createprocess)
     2381        exe = sys.executable
     2382        scriptPath = filepath.FilePath(__file__).sibling("process_cmdline.py")
     2383
     2384        d = defer.Deferred()
     2385        processProto = TrivialProcessProtocol(d)
     2386        comspec = str(os.environ["COMSPEC"])
     2387        cmd = [comspec, "/c", exe, scriptPath.path]
     2388        _dumbwin32proc.Process(reactor, processProto, None, cmd, {}, None)
     2389        yield d
     2390        self.assertEqual(flags,
     2391                         [_dumbwin32proc.win32process.CREATE_NO_WINDOW])
     2392
     2393
     2394
    23532395class UtilTestCase(unittest.TestCase):
    23542396    """
    23552397    Tests for process-related helper functions (currently only
     
    25532595    Win32ProcessTestCase.skip = skipMessage
    25542596    TestTwoProcessesNonPosix.skip = skipMessage
    25552597    Dumbwin32procPidTest.skip = skipMessage
     2598    Win32CreateProcessFlagsTest.skip = skipMessage
    25562599    Win32UnicodeEnvironmentTest.skip = skipMessage
    25572600
    25582601if not interfaces.IReactorProcess(reactor, None):
  • twisted/topfiles/5726.bugfix

    === added file 'twisted/topfiles/5726.bugfix'
     
     1spawnProcess no longer opens an unwanted console on Windows