Skip to content

Commit

Permalink
Allowed writing output to os.devnull
Browse files Browse the repository at this point in the history
  • Loading branch information
elceef committed May 22, 2023
1 parent 79583ae commit 430ba2a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion dnstwist.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,8 +1231,9 @@ def signal_handler(signal, frame):
parser.error(err)

if args.output:
sys._stdout = sys.stdout
try:
sys.stdout = open(args.output, 'x')
sys.stdout = open(args.output, 'w' if args.output == os.devnull else 'x')
except FileExistsError:
parser.error('file already exists: %s' % args.output)
except FileNotFoundError:
Expand Down Expand Up @@ -1297,6 +1298,7 @@ def signal_handler(signal, frame):

if args.format == 'list':
print(Format(domains).list())
sys.stdout = sys._stdout
return list(map(dict, domains)) if kwargs else None

if not MODULE_DNSPYTHON:
Expand Down Expand Up @@ -1436,6 +1438,8 @@ def signal_handler(signal, frame):
elif args.format == 'cli':
print(Format(domains).cli())

sys.stdout = sys._stdout

if kwargs:
return list(map(dict, domains))

Expand Down

0 comments on commit 430ba2a

Please sign in to comment.