GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — move processing of `-WorkingDirectory` before processing of profiles · PowerShell/PowerShell@b51af84

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/Microsoft.PowerShell.ConsoleHost/host/msh
    • ConsoleHost.cs
  • test/powershell/Host
    • ConsoleHost.Tests.ps1
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs‎

Copy file name to clipboardExpand all lines: src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
+25-25Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,31 @@ private void DoRunspaceInitialization(bool skipProfiles, string initialCommand,
16141614

16151615
Executor exec = new Executor(this, false, false);
16161616

1617+
// If working directory was specified, set it
1618+
if (s_cpp != null && s_cpp.WorkingDirectory != null)
1619+
{
1620+
Pipeline tempPipeline = exec.CreatePipeline();
1621+
var command = new Command("Set-Location");
1622+
command.Parameters.Add("LiteralPath", s_cpp.WorkingDirectory);
1623+
tempPipeline.Commands.Add(command);
1624+
1625+
Exception exception;
1626+
if (IsRunningAsync)
1627+
{
1628+
exec.ExecuteCommandAsyncHelper(tempPipeline, out exception, Executor.ExecutionOptions.AddOutputter);
1629+
}
1630+
else
1631+
{
1632+
exec.ExecuteCommandHelper(tempPipeline, out exception, Executor.ExecutionOptions.AddOutputter);
1633+
}
1634+
1635+
if (exception != null)
1636+
{
1637+
_lastRunspaceInitializationException = exception;
1638+
ReportException(exception, exec);
1639+
}
1640+
}
1641+
16171642
if (!string.IsNullOrEmpty(configurationName))
16181643
{
16191644
// If an endpoint configuration is specified then create a loop-back remote runspace targeting
@@ -1694,31 +1719,6 @@ private void DoRunspaceInitialization(bool skipProfiles, string initialCommand,
16941719
TelemetryAPI.ReportStartupTelemetry(this);
16951720
#endif
16961721

1697-
// If working directory was specified, set it
1698-
if (s_cpp != null && s_cpp.WorkingDirectory != null)
1699-
{
1700-
Pipeline tempPipeline = exec.CreatePipeline();
1701-
var command = new Command("Set-Location");
1702-
command.Parameters.Add("LiteralPath", s_cpp.WorkingDirectory);
1703-
tempPipeline.Commands.Add(command);
1704-
1705-
Exception exception;
1706-
if (IsRunningAsync)
1707-
{
1708-
exec.ExecuteCommandAsyncHelper(tempPipeline, out exception, Executor.ExecutionOptions.AddOutputter);
1709-
}
1710-
else
1711-
{
1712-
exec.ExecuteCommandHelper(tempPipeline, out exception, Executor.ExecutionOptions.AddOutputter);
1713-
}
1714-
1715-
if (exception != null)
1716-
{
1717-
_lastRunspaceInitializationException = exception;
1718-
ReportException(exception, exec);
1719-
}
1720-
}
1721-
17221722
// If a file was specified as the argument to run, then run it...
17231723
if (s_cpp != null && s_cpp.File != null)
17241724
{
Collapse file

‎test/powershell/Host/ConsoleHost.Tests.ps1‎

Copy file name to clipboardExpand all lines: test/powershell/Host/ConsoleHost.Tests.ps1
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,25 @@ foo
567567
$LASTEXITCODE | Should -Be $ExitCodeBadCommandLineParameter
568568
$output | Should -Not -BeNullOrEmpty
569569
}
570+
571+
It "-WorkingDirectory should be processed before profiles" {
572+
573+
$currentProfile = Get-Content $PROFILE
574+
@"
575+
(Get-Location).Path
576+
Set-Location $testdrive
577+
"@ > $PROFILE
578+
579+
try {
580+
$out = pwsh -workingdirectory ~ -c '(Get-Location).Path'
581+
$out | Should -HaveCount 2
582+
$out[0] | Should -BeExactly (Get-Item ~).FullName
583+
$out[1] | Should -BeExactly "$testdrive"
584+
}
585+
finally {
586+
Set-Content $PROFILE -Value $currentProfile
587+
}
588+
}
570589
}
571590
}
572591

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.