Resolve the working directory as literal path for Start-Process when it's not specified (#11946)

This commit is contained in:
Bryan Berns
2020-06-09 10:27:53 -07:00
committed by GitHub
parent 2ea18ee6c9
commit edf7cc0ead
2 changed files with 12 additions and 1 deletions
@@ -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"))
@@ -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