File tree 2 files changed +21
-7
lines changed
2 files changed +21
-7
lines changed Original file line number Diff line number Diff line change 15
15
import multiprocessing
16
16
import casanova
17
17
import shlex
18
- import platform
19
18
from casanova .exceptions import MissingColumnError
20
19
from contextlib import ExitStack
21
20
35
34
from minet .cli .argparse import resolve_arg_dependencies , build_parser , get_subparser
36
35
from minet .cli .exceptions import NotResumableError , InvalidArgumentsError , FatalError
37
36
38
- WINDOWS = "windows" in platform .system ().lower ()
39
37
40
38
GLOBAL_SETUP_IS_DONE = False
41
39
@@ -48,11 +46,6 @@ def global_setup() -> None:
48
46
49
47
GLOBAL_SETUP_IS_DONE = True
50
48
51
- # Issue #497, utf-8 encoding for windows stdout
52
- if WINDOWS :
53
- sys .__stdout__ .reconfigure (encoding = "utf-8" )
54
- sys .__stderr__ .reconfigure (encoding = "utf-8" )
55
-
56
49
# Freezing multiprocessing support for pyinstaller etc.
57
50
multiprocessing .freeze_support ()
58
51
Original file line number Diff line number Diff line change @@ -139,7 +139,28 @@ def emit(self, record):
139
139
def acquire_cross_platform_stdout ():
140
140
# As per #254: stdout need to be wrapped so that windows get a correct csv
141
141
# stream output
142
+ # As per #905: powershell sometimes writes a UTF-16-LE BOM in the stdout
143
+ # before one has any chance to reconfigure the stream as UTF-8
144
+ # Reference: https://stackoverflow.com/questions/68487529/how-to-ensure-python-prints-utf-8-and-not-utf-16-le-when-piped-in-powershell
142
145
if "windows" in platform .system ().lower ():
146
+ console .vprint (
147
+ [
148
+ "You piped the result of your command into stdout." ,
149
+ 'Stdout piping (">") is known to be unreliable on Windows shells (cmd.exe, PowerShell)' ,
150
+ "and can sometimes result in corrupted data." ,
151
+ "" ,
152
+ "Are you sure you know what you are doing?" ,
153
+ "If you are not sure, please use the --output flag instead." ,
154
+ "" ,
155
+ ],
156
+ style = "warning" ,
157
+ )
158
+
159
+ # As per #497: we reconfigure the stdout to be UTF-8 on
160
+ # windows
161
+ sys .__stdout__ .reconfigure (encoding = "utf-8" )
162
+ sys .__stderr__ .reconfigure (encoding = "utf-8" )
163
+
143
164
return open (
144
165
sys .__stdout__ .fileno (),
145
166
mode = sys .__stdout__ .mode ,
You can’t perform that action at this time.
0 commit comments