From 6aed9982f6a59857a4702034d8286ba32bdce73e Mon Sep 17 00:00:00 2001 From: douboer Date: Tue, 23 Jun 2020 14:39:29 +0800 Subject: [PATCH] kindle manager --- kman.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/kman.py b/kman.py index 2475426..939579d 100644 --- a/kman.py +++ b/kman.py @@ -568,15 +568,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: