From edf7cc0ead8cb774941cdf6368953a6a79704093 Mon Sep 17 00:00:00 2001 From: Bryan Berns Date: Tue, 9 Jun 2020 13:27:53 -0400 Subject: [PATCH] Resolve the working directory as literal path for `Start-Process` when it's not specified (#11946) --- .../commands/management/Process.cs | 2 +- .../Start-Process.Tests.ps1 | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs index 9166557511..552e353131 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs @@ -1896,7 +1896,7 @@ namespace Microsoft.PowerShell.Commands else { // Working Directory not specified -> Assign Current Path. - startInfo.WorkingDirectory = ResolveFilePath(this.SessionState.Path.CurrentFileSystemLocation.Path); + startInfo.WorkingDirectory = PathUtils.ResolveFilePath(this.SessionState.Path.CurrentFileSystemLocation.Path, this, isLiteralPath: true); } if (this.ParameterSetName.Equals("Default")) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Start-Process.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Start-Process.Tests.ps1 index 1906b6d90c..c097d9700f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Start-Process.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Start-Process.Tests.ps1 @@ -15,6 +15,8 @@ Describe "Start-Process" -Tag "Feature","RequireAdminOnWindows" { $pingCommand = (Get-Command -CommandType Application ping)[0].Definition $pingDirectory = Split-Path $pingCommand -Parent $tempFile = Join-Path -Path $TestDrive -ChildPath PSTest + $tempDirectory = Join-Path -Path $TestDrive -ChildPath 'PSPath[]' + New-Item $tempDirectory -ItemType Directory -Force $assetsFile = Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath SortTest.txt if ($IsWindows) { $pingParam = "-n 2 localhost" @@ -69,6 +71,15 @@ Describe "Start-Process" -Tag "Feature","RequireAdminOnWindows" { $process.Id | Should -BeGreaterThan 1 # $process.ProcessName | Should -Be "ping" } + + It "Should work correctly within an unspecified WorkingDirectory with wildcard-type characters" { + Push-Location -LiteralPath $tempDirectory + $process = Start-Process ping -ArgumentList $pingParam -PassThru -RedirectStandardOutput "$TESTDRIVE/output" @extraArgs + $process.Length | Should -Be 1 + $process.Id | Should -BeGreaterThan 1 + # $process.ProcessName | Should -Be "ping" + Pop-Location + } It "Should handle stderr redirection without error" { $process = Start-Process ping -ArgumentList $pingParam -PassThru -RedirectStandardError $tempFile -RedirectStandardOutput "$TESTDRIVE/output" @extraArgs