Skip to content

"Actual" current directory and PowerShell current directory mismatch when using .NET BCL methods #3428

@antiufo

Description

@antiufo

When cd is used, the actual current directory of the process is not changed. This means that plain BCL methods still see the old current directory.

This creates an inconsistency with other ways of executing commands:

  • PowerShell cmdlets: $pwd is honored
  • External commands: $pwd is honored
  • .NET methods: $pwd is not honored

Steps to reproduce

PS C:\Users\Andrea> cd C:\temp
PS C:\temp> echo example1 > example1.txt
PS C:\temp> [IO.File]::WriteAllText('example2.txt', 'example2')

Expected behavior

C:\temp contains example1.txt and example2.txt.

Actual behavior

C:\temp only contains example1.txt. example2.txt is created in C:\Users\Andrea.

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.15063.0
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.15063.0
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Btw the same happens with PowerShell v6.0.0-alpha.17.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-By DesignThe reported behavior is by design.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions