@@ -3777,6 +3777,34 @@ def test_startupinfo_copy(self):
37773777 self .assertEqual (startupinfo .wShowWindow , subprocess .SW_HIDE )
37783778 self .assertEqual (startupinfo .lpAttributeList , {"handle_list" : []})
37793779
3780+ def test_startupinfo_shell_show_window (self ):
3781+ # gh-85028: shell=True must not override wShowWindow set by the caller
3782+ import _winapi
3783+ SW_MAXIMIZE = 3
3784+ used = []
3785+ create_process = _winapi .CreateProcess
3786+
3787+ def spy (* args ):
3788+ # The startup info is the last argument of CreateProcess()
3789+ used .append (args [- 1 ])
3790+ return create_process (* args )
3791+
3792+ startupinfo = subprocess .STARTUPINFO (
3793+ dwFlags = subprocess .STARTF_USESHOWWINDOW ,
3794+ wShowWindow = SW_MAXIMIZE )
3795+ with mock .patch .object (_winapi , 'CreateProcess' , spy ):
3796+ rc = subprocess .call (ZERO_RETURN_CMD , shell = True ,
3797+ startupinfo = startupinfo )
3798+ self .assertEqual (rc , 0 )
3799+ rc = subprocess .call (ZERO_RETURN_CMD , shell = True )
3800+ self .assertEqual (rc , 0 )
3801+
3802+ requested , default = used
3803+ self .assertEqual (requested .wShowWindow , SW_MAXIMIZE )
3804+ # Without STARTF_USESHOWWINDOW the shell window is still hidden.
3805+ self .assertTrue (default .dwFlags & subprocess .STARTF_USESHOWWINDOW )
3806+ self .assertEqual (default .wShowWindow , subprocess .SW_HIDE )
3807+
37803808 # CREATE_NEW_CONSOLE creates a "popup" window.
37813809 @support .requires_resource ('gui' )
37823810 def test_creationflags (self ):
0 commit comments