This commit is contained in:
gavin
2020-06-26 11:28:43 +08:00

15
kman.py
View File

@@ -571,15 +571,24 @@ class kMan:
# not test for windows & linux
with subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, \
stderr=subprocess.PIPE, bufsize=-1) as s:
stream_stdout = io.TextIOWrapper(s.stdout, encoding='utf-8')
stream_stderr = io.TextIOWrapper(s.stderr, encoding='utf-8')
#Windows:
# UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 48:
# invalid continuation byte
#stream_stdout = io.TextIOWrapper(s.stdout, encoding='utf-8')
#stream_stderr = io.TextIOWrapper(s.stderr, encoding='utf-8')
stream_stdout = io.TextIOWrapper(s.stdout, encoding='GBK')
stream_stderr = io.TextIOWrapper(s.stderr, encoding='GBK')
sout = str(stream_stdout.read())
#serr = str(stream_stderr.read())
#if sout: print('stdout {}'.format(sout))
#if serr: print('stderr {}'.format(serr))
print('os.name {} sout {}'.format(os.name,sout))
if os.name == 'nt': # windows
for d in sout.split('\n'):
if 'Kindle' in d: return d.split('\s+')[0]
if 'Kindle' in d:
p = re.split(r'\s+',d)[0]
print('path {}'.format(p))
return p
elif os.name == 'posix': # mac os
if sout: return('/Volumes/Kindle/')
else: