Skip to content

PowerShellLocator doesn't seem to be working as expected #3132

@filzrev

Description

@filzrev

Currently PowerShellLocator seems not working as expected.

It's always resolved to Windows PowerShell and pwsh seems not be used.

Problems

1. Wrong subdirectories are selected
https://github.com/dotnet/BenchmarkDotNet/blob/605cd1f3ed8e22def7ef1b8adfc6f7f4937f0051/src/BenchmarkDotNet/Helpers/PowerShellLocator.cs#L36C100-L41

Currently, all subdirectories are listed up (e.g. 7\zh-Hant) and regex seems not working as expected.
Because regex is using partial match. and testing with full path.

It needs following changes.

  • Use SearchOption.TopDirectoryOnly
  • Use Regex.IsMatch(Path.GetFileName(x), "^[0-9]+$") to filter by directory name.

2. -Command argument is required to run command with pwsh
When using pwsh to execute command. It need to specify -Command argument explicitly.

3. ANSI escape sequence is added when running command with pwsh
It need to use | Out-String to suppress ANSI escape sequence.

$"Get-CimInstance Win32_Processor -Property {argList} | Format-List {argList}");

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