Skip to content

Commit 52e7a45

Browse files
committed
Fix crash when stdout is not a TTY on Linux
Without this change, the following happened when piping/redirecting the output of MCE.py: ``` Error: MC Extractor v1.102.0 crashed, please report the following: Traceback (most recent call last): File "/root/MCExtractor/MCE.py", line 1093, in <module> elif sys_os.startswith('linux') or sys_os == 'darwin' or sys_os.find('bsd') != -1 : sys.stdout.write('\x1b]2;' + mce_title + '\x07') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/colorama/ansitowin32.py", line 47, in write self.__convertor.write(text) File "/usr/lib/python3/dist-packages/colorama/ansitowin32.py", line 177, in write self.write_and_convert(text) File "/usr/lib/python3/dist-packages/colorama/ansitowin32.py", line 199, in write_and_convert text = self.convert_osc(text) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/colorama/ansitowin32.py", line 272, in convert_osc winterm.set_title(params[1]) ^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'set_title' ``` This looks like a colorama bug, see tartley/colorama#209. The workaround is to skip the title change if stdout is not a TTY.
1 parent a220258 commit 52e7a45

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

MCE.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ def mass_scan(f_path) :
10901090

10911091
# Set console/shell window title
10921092
if sys_os == 'win32' : ctypes.windll.kernel32.SetConsoleTitleW(mce_title)
1093-
elif sys_os.startswith('linux') or sys_os == 'darwin' or sys_os.find('bsd') != -1 : sys.stdout.write('\x1b]2;' + mce_title + '\x07')
1093+
elif (sys_os.startswith('linux') or sys_os == 'darwin' or sys_os.find('bsd') != -1) and sys.stdout.isatty() : sys.stdout.write('\x1b]2;' + mce_title + '\x07')
10941094

10951095
if not param.skip_intro :
10961096
mce_hdr(mce_title)

0 commit comments

Comments
 (0)