Skip to content

Commit 95683c0

Browse files
nekwoteknium1
authored andcommitted
fix(windows): hide local subprocess consoles
Apply Windows CREATE_NO_WINDOW flags to foreground local terminal subprocesses and tracked background processes so Hermes operations do not flash or steal focus with extra console windows.
1 parent f007ef8 commit 95683c0

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

tools/environments/local.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from pathlib import Path
1313

1414
from tools.environments.base import BaseEnvironment, _pipe_stdin
15+
from hermes_cli._subprocess_compat import windows_hide_flags
1516

1617
_IS_WINDOWS = platform.system() == "Windows"
1718

@@ -519,6 +520,8 @@ def _run_bash(self, cmd_string: str, *, login: bool = False,
519520

520521
_popen_cwd = self.cwd
521522

523+
_popen_kwargs = {"creationflags": windows_hide_flags()} if _IS_WINDOWS else {}
524+
522525
proc = subprocess.Popen(
523526
args,
524527
text=True,
@@ -531,6 +534,7 @@ def _run_bash(self, cmd_string: str, *, login: bool = False,
531534
preexec_fn=None if _IS_WINDOWS else os.setsid,
532535
creationflags=subprocess.CREATE_NO_WINDOW if _IS_WINDOWS else 0,
533536
cwd=_popen_cwd,
537+
**_popen_kwargs,
534538
)
535539
if not _IS_WINDOWS:
536540
try:

tools/process_registry.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
_IS_WINDOWS = platform.system() == "Windows"
4444
from tools.environments.local import _find_shell, _resolve_safe_cwd, _sanitize_subprocess_env
45+
from hermes_cli._subprocess_compat import windows_hide_flags
4546
from dataclasses import dataclass, field
4647
from typing import Any, Dict, List, Optional
4748

@@ -549,6 +550,8 @@ def spawn_local(
549550
# stdout is a pipe, hiding output from process(action="poll")).
550551
bg_env = _sanitize_subprocess_env(os.environ, env_vars)
551552
bg_env["PYTHONUNBUFFERED"] = "1"
553+
_popen_kwargs = {"creationflags": windows_hide_flags()} if _IS_WINDOWS else {}
554+
552555
proc = subprocess.Popen(
553556
[user_shell, "-lic", f"set +m; {command}"],
554557
text=True,
@@ -560,7 +563,7 @@ def spawn_local(
560563
stderr=subprocess.STDOUT,
561564
stdin=subprocess.DEVNULL,
562565
preexec_fn=None if _IS_WINDOWS else os.setsid,
563-
creationflags=subprocess.CREATE_NO_WINDOW if _IS_WINDOWS else 0,
566+
**_popen_kwargs,
564567
)
565568

566569
session.process = proc

0 commit comments

Comments
 (0)