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

Fix path bug in Ubuntu #1708

Merged
merged 3 commits into from
Aug 27, 2024
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: 18 additions & 3 deletions bbot/core/helpers/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import logging
import traceback
from signal import SIGINT
from subprocess import CompletedProcess, CalledProcessError
from subprocess import CompletedProcess, CalledProcessError, SubprocessError

from .misc import smart_decode, smart_encode
from .misc import smart_decode, smart_encode, which

log = logging.getLogger("bbot.core.helpers.command")

Expand Down Expand Up @@ -182,7 +182,11 @@ async def _spawn_proc(self, *command, **kwargs):
>>> _spawn_proc("ls", "-l", input="data")
(<Process ...>, "data", ["ls", "-l"])
"""
command, kwargs = self._prepare_command_kwargs(command, kwargs)
try:
command, kwargs = self._prepare_command_kwargs(command, kwargs)
except SubprocessError as e:
log.warning(e)
return None, None, None
_input = kwargs.pop("input", None)
if _input is not None:
if kwargs.get("stdin") is not None:
Expand Down Expand Up @@ -276,6 +280,17 @@ def _prepare_command_kwargs(self, command, kwargs):
command = command[0]
command = [str(s) for s in command]

if not command:
raise SubprocessError("Must specify a command")

# use full path of binary, if not already specified
binary = command[0]
if not "/" in binary:
binary_full_path = which(binary)
if binary_full_path is None:
raise SubprocessError(f'Command "{binary}" was not found')
command[0] = binary_full_path

env = kwargs.get("env", os.environ)
if sudo and os.geteuid() != 0:
self.depsinstaller.ensure_root()
Expand Down
Loading