Skip to content

PowerShell doesn't use the final target of a symbolic link when starting a process or running a native command on Windows #16171

@daxian-dbw

Description

@daxian-dbw

Prerequisites

Steps to reproduce

On Windows

  1. Open an elevated pwsh session, and create 2 symbolic links as follows in a folder:
    New-Item -ItemType SymbolicLink -Path pwsh-symlink -Value $pshome\pwsh.exe
    New-Item -ItemType SymbolicLink -Path pwsh-double-link -Value .\pwsh-symlink
    
  2. Under the same folder, run .\pwsh-symlink, and you will see pwsh console window pops up.
  3. Under the same folder, run .\pwsh-double-link, and you will see the "How do you want to open this file" window pops up.

Note: Start-Process doesn't use the final target of a symbolic link either.


However, it works fine on Unix

  1. Create 2 symbolic links as follows in a folder:
    /bin/ln -s /opt/microsoft/powershell/7/pwsh pwsh-link
    /bin/ln -s /home/<user>/tmp/pwsh-link /home/<user>/tmp/pwsh-double
    
  2. Under the same folder, run ./pwsh-link -c 1+1, and you will get 2 printed out as the result.
  3. Under the same folder, run ./pwsh-double -c 1+1, and you will get 2 printed out as the result.

Expected behavior

On Windows:
1. pwsh should know that `pwsh-symlink` is actually a console application, and run into with the current console.
2. pwsh should be able to run `pwsh-double-link`, just like on Unix platforms.

Actual behavior

On Windows
1. pwsh opens `pwsh-symlink` in a separate console window, which means it doesn't use the link target to check if it's a console application, and thus starts the process with 'UseShellExecute = true'.
2. pwsh cannot run `pwsh-double-link`, because when using `UseShellExecute`, the Shell automatically uses the immediate link target of a symbolic link file, but doesn't do recursive resolution when the immediate link target is again a symbolic link.

Error details

No response

Environment data

The latest build from master, and happen on all 7.2.0-preview.9 as well

Visuals

image

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productNeeds-InvestigationThe behavior reported in the issue is unexpected and needs further investigation.Resolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions