Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use encoding=utf-8 when reading child stdout #88

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions lglpy/android/adb.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,12 @@ def adb(self, *args: str, text: bool = True, shell: bool = False,
commands = self.get_base_command(args)
packed_commands = self.pack_commands(commands, shell, quote)

# Force UTF-8 for text output
encoding = 'utf-8' if text else None

# Invoke the command
rep = sp.run(packed_commands, check=check, shell=shell, text=text,
rep = sp.run(packed_commands, check=check, shell=shell,
text=text, encoding=encoding,
stdin=sp.DEVNULL, stdout=sp.PIPE, stderr=sp.PIPE)

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

# Force UTF-8 for text output
encoding = 'utf-8' if text else None

# Sink inputs to DEVNULL to stop the child process stealing keyboard
# Sink outputs to DEVNULL to stop full output buffers blocking child
# pylint: disable=consider-using-with
process = sp.Popen(packed_commands,
text=text, shell=shell,
text=text, encoding=encoding, shell=shell,
stdin=sp.DEVNULL, stdout=output, stderr=sp.DEVNULL)

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

# Force UTF-8 for text output
encoding = 'utf-8' if text else None

# Invoke the command
rep = sp.run(packed_commands,
check=check, shell=shell, text=text,
check=check, shell=shell, text=text, encoding=encoding,
stdin=sp.DEVNULL, stdout=sp.PIPE, stderr=sp.PIPE)

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

# Force UTF-8 for text output
encoding = 'utf-8' if text else None

# Invoke the command
rep = sp.run(packed_commands,
check=check, shell=shell, text=text,
check=check, shell=shell, text=text, encoding=encoding,
stdin=sp.DEVNULL, stdout=sp.PIPE, stderr=sp.PIPE)

# Return the output
Expand Down