Skip to content

Commit f55b675

Browse files
committed
Fix Click output bug, sometimes preventing scans to work properly on Windows
1 parent d8c218c commit f55b675

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/pyspector/cli.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ def _dbg(debug: bool, msg: str = "", **style_kwargs) -> None:
6666
click.echo(msg)
6767

6868

69+
def _write_stdout(text: str) -> None:
70+
"""Write text to stdout without going through Click's Windows console shim."""
71+
stream = getattr(sys, "__stdout__", None) or sys.stdout
72+
stream.write(text)
73+
stream.flush()
74+
75+
6976
_BANNER = r"""
7077
o__ __o o__ __o o
7178
<| v\ /v v\ <|>
@@ -890,7 +897,7 @@ def _execute_scan(
890897
except IOError as e:
891898
click.echo(click.style(f"Error writing to output file: {e}", fg="red"))
892899
else:
893-
click.echo(output)
900+
_write_stdout(output)
894901

895902
end_time = time.time()
896903
_dbg(

0 commit comments

Comments
 (0)