Fixed stdio flows
This commit is contained in:
+6
-2
@@ -139,7 +139,9 @@ if __name__ == '__main__': # main app start
|
|||||||
else:
|
else:
|
||||||
infd = open(args.input_file, mode='rb')
|
infd = open(args.input_file, mode='rb')
|
||||||
indata = infd.read()
|
indata = infd.read()
|
||||||
if infd != sys.stdin:
|
if infd == sys.stdin: # perform additional conversion
|
||||||
|
indata = indata.encode('utf-8')
|
||||||
|
else:
|
||||||
infd.close()
|
infd.close()
|
||||||
except:
|
except:
|
||||||
print('Error reading the input data!')
|
print('Error reading the input data!')
|
||||||
@@ -171,10 +173,12 @@ if __name__ == '__main__': # main app start
|
|||||||
try:
|
try:
|
||||||
if args.output_file == '-':
|
if args.output_file == '-':
|
||||||
outfd = sys.stdout
|
outfd = sys.stdout
|
||||||
|
if type(outdata) == type(b''):
|
||||||
|
outdata = outdata.decode('utf-8')
|
||||||
outfd.write(outdata)
|
outfd.write(outdata)
|
||||||
else:
|
else:
|
||||||
outfd = open(args.output_file, mode='wb')
|
outfd = open(args.output_file, mode='wb')
|
||||||
if type(outdata) == 'str':
|
if type(outdata) == type(''):
|
||||||
outdata = outdata.encode('utf-8')
|
outdata = outdata.encode('utf-8')
|
||||||
outfd.write(outdata)
|
outfd.write(outdata)
|
||||||
if outfd != sys.stdout:
|
if outfd != sys.stdout:
|
||||||
|
|||||||
Reference in New Issue
Block a user