Skip to content

Commit df18cad

Browse files
authored
More efficient Windows codepage post processing fix (without spawning process)
1 parent a49de53 commit df18cad

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

bazarr/subtitles/post_processing.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ def postprocessing(command, path):
1212
try:
1313
encoding = getpreferredencoding()
1414
if os.name == 'nt':
15-
codepage = subprocess.Popen("chcp", shell=True, stdout=subprocess.PIPE,
16-
stderr=subprocess.PIPE)
17-
out_codepage, err_codepage = codepage.communicate()
18-
enc_raw = out_codepage.decode('ascii', errors='ignore').split(':')[-1].strip().rstrip('.')
19-
encoding = 'cp' + enc_raw if enc_raw.isdigit() else enc_raw
20-
15+
from ctypes import windll
16+
code_page = windll.kernel32.GetConsoleOutputCP()
17+
encoding = f"cp{code_page}"
18+
2119
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,
2220
stderr=subprocess.PIPE, encoding=encoding)
2321
# wait for the process to terminate

0 commit comments

Comments
 (0)