Skip to content

[Bug]: resolvePowerShellPath() on Windows ignores PowerShell 7, defaults to PS 5.1 #25638

@Yoheoline

Description

@Yoheoline

Description

On Windows, resolvePowerShellPath() in the exec runtime always resolves to PowerShell 5.1 (powershell.exe) even when PowerShell 7 (pwsh.exe) is installed at C:\Program Files\PowerShell\7\pwsh.exe.

This causes exec tool commands using && operator to fail silently or error out, because PowerShell 5.1 does not support && (pipeline chain operators were introduced in PowerShell 7).

Steps to Reproduce

  1. Install OpenClaw on Windows 11 with PowerShell 7 installed
  2. Run any exec command using && (e.g. cd /path && ls)
  3. The command fails because it's executed via PS 5.1 which doesn't support &&

Current Behavior

resolvePowerShellPath() checks:

  1. SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe (PS 5.1)
  2. Falls back to "powershell.exe"

PowerShell 7 (pwsh.exe / C:\Program Files\PowerShell\7\pwsh.exe) is never checked.

Expected Behavior

resolvePowerShellPath() should prioritize PowerShell 7 when available:

  1. Check C:\Program Files\PowerShell\7\pwsh.exe first
  2. Then fall back to PS 5.1

Suggested Fix

function resolvePowerShellPath() {
  // Prefer PowerShell 7 (supports && operator, better compatibility)
  const pwsh7 = "C:\Program Files\PowerShell\7\pwsh.exe";
  if (fs.existsSync(pwsh7)) return pwsh7;
  // Fallback to PS 5.1
  const systemRoot = process.env.SystemRoot || process.env.WINDIR;
  if (systemRoot) {
    const candidate = path.join(systemRoot, "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
    if (fs.existsSync(candidate)) return candidate;
  }
  return "powershell.exe";
}

Environment

  • OS: Windows 11 Home 10.0.26200
  • OpenClaw: 2026.2.17+
  • PowerShell 7.5 installed at C:\Program Files\PowerShell\7\
  • Node.js: v22.x

Workaround

Currently patching resolvePowerShellPath() in dist files after each update via sed/script, but this breaks on every npm update.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions