diff --git a/gallery_dl/__init__.py b/gallery_dl/__init__.py index 6fba5e22..04aff511 100644 --- a/gallery_dl/__init__.py +++ b/gallery_dl/__init__.py @@ -108,7 +108,7 @@ def parse_inputfile(file, log): def main(): try: - if sys.stdout.encoding.lower() != "utf-8": + if sys.stdout and sys.stdout.encoding.lower() != "utf-8": output.replace_std_streams() parser = option.build_parser() diff --git a/gallery_dl/output.py b/gallery_dl/output.py index f0849500..9e2f8a68 100644 --- a/gallery_dl/output.py +++ b/gallery_dl/output.py @@ -149,12 +149,13 @@ def replace_std_streams(errors="replace"): """Replace standard streams and set their error handlers to 'errors'""" for name in ("stdout", "stdin", "stderr"): stream = getattr(sys, name) - setattr(sys, name, stream.__class__( - stream.buffer, - errors=errors, - newline=stream.newlines, - line_buffering=stream.line_buffering, - )) + if stream: + setattr(sys, name, stream.__class__( + stream.buffer, + errors=errors, + newline=stream.newlines, + line_buffering=stream.line_buffering, + )) # --------------------------------------------------------------------