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.
When
cdis 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:
$pwdis honored$pwdis honored$pwdis not honoredSteps to reproduce
Expected behavior
C:\tempcontainsexample1.txtandexample2.txt.Actual behavior
C:\temponly containsexample1.txt.example2.txtis created inC:\Users\Andrea.Environment data
Btw the same happens with PowerShell v6.0.0-alpha.17.