@@ -131,7 +131,17 @@ def _search_via_powershell(self, query: str) -> List[Dict[str, str]]:
131131 cmd = ["powershell" , "-NoProfile" , "-NonInteractive" , "-Command" , ps_script ]
132132 startupinfo = self ._get_startup_info ()
133133
134- proc = subprocess .run (cmd , capture_output = True , text = True , encoding = "utf-8" , errors = "ignore" , startupinfo = startupinfo , timeout = 45 )
134+ # Hide CMD window on Windows
135+ kwargs = {}
136+ if startupinfo :
137+ kwargs ['startupinfo' ] = startupinfo
138+ import sys
139+ if sys .platform == "win32" :
140+ if hasattr (subprocess , 'CREATE_NO_WINDOW' ):
141+ kwargs ['creationflags' ] = subprocess .CREATE_NO_WINDOW
142+ else :
143+ kwargs ['creationflags' ] = 0x08000000 # CREATE_NO_WINDOW constant
144+ proc = subprocess .run (cmd , capture_output = True , text = True , encoding = "utf-8" , errors = "ignore" , timeout = 45 , ** kwargs )
135145
136146 if proc .returncode != 0 :
137147 logger .debug (f"PowerShell search failed: { proc .stderr [:200 ] if proc .stderr else 'No error' } " )
@@ -317,7 +327,17 @@ def install_package(self, package_id: str, scope: str = "machine") -> bool:
317327 "--accept-source-agreements"
318328 ]
319329 try :
320- proc = subprocess .run (cmd , capture_output = True , text = True )
330+ startupinfo = self ._get_startup_info ()
331+ kwargs = {}
332+ if startupinfo :
333+ kwargs ['startupinfo' ] = startupinfo
334+ import sys
335+ if sys .platform == "win32" :
336+ if hasattr (subprocess , 'CREATE_NO_WINDOW' ):
337+ kwargs ['creationflags' ] = subprocess .CREATE_NO_WINDOW
338+ else :
339+ kwargs ['creationflags' ] = 0x08000000 # CREATE_NO_WINDOW constant
340+ proc = subprocess .run (cmd , capture_output = True , text = True , ** kwargs )
321341 if proc .returncode != 0 :
322342 logger .error (f"Winget install failed: { proc .stderr } " )
323343 return False
@@ -330,7 +350,17 @@ def download_package(self, package_id: str, dest_dir: Path) -> Optional[Path]:
330350 """Download a package installer to dest_dir. Returns path to installer if found."""
331351 cmd = ["winget" , "download" , "--id" , package_id , "--dir" , str (dest_dir ), "--accept-source-agreements" , "--accept-package-agreements" ]
332352 try :
333- proc = subprocess .run (cmd , capture_output = True , text = True )
353+ startupinfo = self ._get_startup_info ()
354+ kwargs = {}
355+ if startupinfo :
356+ kwargs ['startupinfo' ] = startupinfo
357+ import sys
358+ if sys .platform == "win32" :
359+ if hasattr (subprocess , 'CREATE_NO_WINDOW' ):
360+ kwargs ['creationflags' ] = subprocess .CREATE_NO_WINDOW
361+ else :
362+ kwargs ['creationflags' ] = 0x08000000 # CREATE_NO_WINDOW constant
363+ proc = subprocess .run (cmd , capture_output = True , text = True , ** kwargs )
334364 if proc .returncode != 0 :
335365 logger .error (f"Winget download failed: { proc .stderr } " )
336366 return None
@@ -351,7 +381,17 @@ def _search_via_cli(self, query: str) -> List[Dict[str, str]]:
351381 cmd = ["winget" , "search" , query , "--accept-source-agreements" ]
352382 startupinfo = self ._get_startup_info ()
353383
354- proc = subprocess .run (cmd , capture_output = True , text = True , encoding = "utf-8" , errors = "ignore" , startupinfo = startupinfo )
384+ # Hide CMD window on Windows
385+ kwargs = {}
386+ if startupinfo :
387+ kwargs ['startupinfo' ] = startupinfo
388+ import sys
389+ if sys .platform == "win32" :
390+ if hasattr (subprocess , 'CREATE_NO_WINDOW' ):
391+ kwargs ['creationflags' ] = subprocess .CREATE_NO_WINDOW
392+ else :
393+ kwargs ['creationflags' ] = 0x08000000 # CREATE_NO_WINDOW constant
394+ proc = subprocess .run (cmd , capture_output = True , text = True , encoding = "utf-8" , errors = "ignore" , ** kwargs )
355395 if proc .returncode != 0 :
356396 return []
357397
0 commit comments