Skip to content

Commit d1f04bb

Browse files
authored
Use utf-8 when reading child stdout (#88)
1 parent 8dcade5 commit d1f04bb

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

lglpy/android/adb.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,12 @@ def adb(self, *args: str, text: bool = True, shell: bool = False,
168168
commands = self.get_base_command(args)
169169
packed_commands = self.pack_commands(commands, shell, quote)
170170

171+
# Force UTF-8 for text output
172+
encoding = 'utf-8' if text else None
173+
171174
# Invoke the command
172-
rep = sp.run(packed_commands, check=check, shell=shell, text=text,
175+
rep = sp.run(packed_commands, check=check, shell=shell,
176+
text=text, encoding=encoding,
173177
stdin=sp.DEVNULL, stdout=sp.PIPE, stderr=sp.PIPE)
174178

175179
# Return the output
@@ -219,11 +223,14 @@ def adb_async(self, *args: str, text: bool = True, shell: bool = False,
219223
commands = self.get_base_command(args)
220224
packed_commands = self.pack_commands(commands, shell, quote)
221225

226+
# Force UTF-8 for text output
227+
encoding = 'utf-8' if text else None
228+
222229
# Sink inputs to DEVNULL to stop the child process stealing keyboard
223230
# Sink outputs to DEVNULL to stop full output buffers blocking child
224231
# pylint: disable=consider-using-with
225232
process = sp.Popen(packed_commands,
226-
text=text, shell=shell,
233+
text=text, encoding=encoding, shell=shell,
227234
stdin=sp.DEVNULL, stdout=output, stderr=sp.DEVNULL)
228235

229236
# Return the output process a user can use to wait, if needed.
@@ -258,9 +265,12 @@ def adb_run(self, *args: str, text: bool = True, shell: bool = False,
258265
commands.extend(args)
259266
packed_commands = self.pack_commands(commands, shell, quote)
260267

268+
# Force UTF-8 for text output
269+
encoding = 'utf-8' if text else None
270+
261271
# Invoke the command
262272
rep = sp.run(packed_commands,
263-
check=check, shell=shell, text=text,
273+
check=check, shell=shell, text=text, encoding=encoding,
264274
stdin=sp.DEVNULL, stdout=sp.PIPE, stderr=sp.PIPE)
265275

266276
# Return the output
@@ -298,9 +308,12 @@ def adb_runas(self, *args: str, text: bool = True, shell: bool = False,
298308
commands.extend(args)
299309
packed_commands = self.pack_commands(commands, shell, quote)
300310

311+
# Force UTF-8 for text output
312+
encoding = 'utf-8' if text else None
313+
301314
# Invoke the command
302315
rep = sp.run(packed_commands,
303-
check=check, shell=shell, text=text,
316+
check=check, shell=shell, text=text, encoding=encoding,
304317
stdin=sp.DEVNULL, stdout=sp.PIPE, stderr=sp.PIPE)
305318

306319
# Return the output

0 commit comments

Comments
 (0)