Skip to content

WindowsWhichCommand

Base classes

Name Children Inherits
WhichCommand
anyenv.os_commands.base
Base class for which/where commands to locate executables.

⋔ Inheritance diagram

graph TD
  1920853082["which.WindowsWhichCommand"]
  2658962468["base.WhichCommand"]
  925645236["abc.ABC"]
  2751680898["builtins.object"]
  2658962468 --> 1920853082
  925645236 --> 2658962468
  2751680898 --> 925645236

🛈 DocStrings

Bases: WhichCommand

Windows where command implementation.

Source code in src/anyenv/os_commands/which.py
class WindowsWhichCommand(WhichCommand):
    """Windows where command implementation."""

    def create_command(self, executable: str) -> str:
        """Generate Windows where command.

        Args:
            executable: Name of executable to find

        Returns:
            The where command string
        """
        return powershell(f"where.exe {ps_literal(executable)}")

    def parse_command(self, output: str, exit_code: int = 0) -> str | None:
        """Parse Windows where result.

        Args:
            output: Raw command output
            exit_code: Command exit code

        Returns:
            Path to first matching executable or None if not found
        """
        if exit_code != 0:
            return None
        # where can return multiple paths, take the first one
        lines = output.strip().splitlines()
        return lines[0].strip() if lines else None

create_command

create_command(executable: str) -> str

Generate Windows where command.

Parameters:

Name Type Description Default
executable str

Name of executable to find

required

Returns:

Type Description
str

The where command string

Source code in src/anyenv/os_commands/which.py
def create_command(self, executable: str) -> str:
    """Generate Windows where command.

    Args:
        executable: Name of executable to find

    Returns:
        The where command string
    """
    return powershell(f"where.exe {ps_literal(executable)}")

parse_command

parse_command(output: str, exit_code: int = 0) -> str | None

Parse Windows where result.

Parameters:

Name Type Description Default
output str

Raw command output

required
exit_code int

Command exit code

0

Returns:

Type Description
str | None

Path to first matching executable or None if not found

Source code in src/anyenv/os_commands/which.py
def parse_command(self, output: str, exit_code: int = 0) -> str | None:
    """Parse Windows where result.

    Args:
        output: Raw command output
        exit_code: Command exit code

    Returns:
        Path to first matching executable or None if not found
    """
    if exit_code != 0:
        return None
    # where can return multiple paths, take the first one
    lines = output.strip().splitlines()
    return lines[0].strip() if lines else None

:fa-brands-github: Show source on GitHub