diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs index 0ac97156103..30bb4617bec 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs @@ -29,11 +29,6 @@ namespace Microsoft.PowerShell.Commands { - // 2004/12/17-JonN ProcessNameGlobAttribute was deeply wrong. - // For example, if you pass in a single Process, it will match - // all processes with the same name. - // I have removed the globbing code. - #region ProcessBaseCommand /// /// This class implements the base for process commands @@ -461,7 +456,6 @@ public sealed class GetProcessCommand : ProcessBaseCommand /// /// Has the list of process names on which to this command will work /// - // [ProcessNameGlobAttribute] [Parameter(Position = 0, ParameterSetName = NameParameterSet, ValueFromPipelineByPropertyName = true)] [Parameter(Position = 0, ParameterSetName = NameWithUserNameParameterSet, ValueFromPipelineByPropertyName = true)] [Alias("ProcessName")] @@ -1062,7 +1056,6 @@ public sealed class StopProcessCommand : ProcessBaseCommand /// /// Has the list of process names on which to this command will work /// - // [ProcessNameGlobAttribute] [Parameter( ParameterSetName = "Name", Mandatory = true, @@ -1618,7 +1611,6 @@ public sealed class StartProcessCommand : PSCmdlet, IDisposable /// [Parameter(Position = 1)] [Alias("Args")] - [ValidateNotNullOrEmpty] [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] public string[] ArgumentList { get; set; } 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 4f968679851..fa9789c7f58 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Start-Process.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Start-Process.Tests.ps1 @@ -6,6 +6,10 @@ Describe "Start-Process" -Tags @("Feature") { $isNanoServer = [System.Management.Automation.Platform]::IsNanoServer $isIot = [System.Management.Automation.Platform]::IsIoT $isFullWin = $IsWindows -and !$isNanoServer -and !$isIot + $extraArgs = @{} + if ($isFullWin) { + $extraArgs.WindowStyle = "Hidden" + } $pingCommand = (Get-Command -CommandType Application ping)[0].Definition $pingDirectory = Split-Path $pingCommand -Parent @@ -23,7 +27,7 @@ Describe "Start-Process" -Tags @("Feature") { # This has been fixed on Linux, but not on macOS It "Should process arguments without error" { - $process = Start-Process ping -ArgumentList $pingParam -PassThru -RedirectStandardOutput "$TESTDRIVE/output" + $process = Start-Process ping -ArgumentList $pingParam -PassThru -RedirectStandardOutput "$TESTDRIVE/output" @extraArgs $process.Length | Should -Be 1 $process.Id | Should -BeGreaterThan 1 @@ -31,7 +35,7 @@ Describe "Start-Process" -Tags @("Feature") { } It "Should work correctly when used with full path name" { - $process = Start-Process $pingCommand -ArgumentList $pingParam -PassThru -RedirectStandardOutput "$TESTDRIVE/output" + $process = Start-Process $pingCommand -ArgumentList $pingParam -PassThru -RedirectStandardOutput "$TESTDRIVE/output" @extraArgs $process.Length | Should -Be 1 $process.Id | Should -BeGreaterThan 1 @@ -39,7 +43,7 @@ Describe "Start-Process" -Tags @("Feature") { } It "Should invoke correct path when used with FilePath argument" { - $process = Start-Process -FilePath $pingCommand -ArgumentList $pingParam -PassThru -RedirectStandardOutput "$TESTDRIVE/output" + $process = Start-Process -FilePath $pingCommand -ArgumentList $pingParam -PassThru -RedirectStandardOutput "$TESTDRIVE/output" @extraArgs $process.Length | Should -Be 1 $process.Id | Should -BeGreaterThan 1 @@ -47,18 +51,18 @@ Describe "Start-Process" -Tags @("Feature") { } It "Should invoke correct path when used with Path alias argument" { - $process = Start-Process -Path $pingCommand -ArgumentList $pingParam -PassThru -RedirectStandardOutput "$TESTDRIVE/output" + $process = Start-Process -Path $pingCommand -ArgumentList $pingParam -PassThru -RedirectStandardOutput "$TESTDRIVE/output" @extraArgs $process.Length | Should -Be 1 $process.Id | Should -BeGreaterThan 1 } It "Should wait for command completion if used with Wait argument" { - $process = Start-Process ping -ArgumentList $pingParam -Wait -PassThru -RedirectStandardOutput "$TESTDRIVE/output" + $process = Start-Process ping -ArgumentList $pingParam -Wait -PassThru -RedirectStandardOutput "$TESTDRIVE/output" @extraArgs } It "Should work correctly with WorkingDirectory argument" { - $process = Start-Process ping -WorkingDirectory $pingDirectory -ArgumentList $pingParam -PassThru -RedirectStandardOutput "$TESTDRIVE/output" + $process = Start-Process ping -WorkingDirectory $pingDirectory -ArgumentList $pingParam -PassThru -RedirectStandardOutput "$TESTDRIVE/output" @extraArgs $process.Length | Should -Be 1 $process.Id | Should -BeGreaterThan 1 @@ -66,7 +70,7 @@ Describe "Start-Process" -Tags @("Feature") { } It "Should handle stderr redirection without error" { - $process = Start-Process ping -ArgumentList $pingParam -PassThru -RedirectStandardError $tempFile -RedirectStandardOutput "$TESTDRIVE/output" + $process = Start-Process ping -ArgumentList $pingParam -PassThru -RedirectStandardError $tempFile -RedirectStandardOutput "$TESTDRIVE/output" @extraArgs $process.Length | Should -Be 1 $process.Id | Should -BeGreaterThan 1 @@ -74,14 +78,14 @@ Describe "Start-Process" -Tags @("Feature") { } It "Should handle stdout redirection without error" { - $process = Start-Process ping -ArgumentList $pingParam -Wait -RedirectStandardOutput $tempFile + $process = Start-Process ping -ArgumentList $pingParam -Wait -RedirectStandardOutput $tempFile @extraArgs $dirEntry = get-childitem $tempFile $dirEntry.Length | Should -BeGreaterThan 0 } # Marking this test 'pending' to unblock daily builds. Filed issue : https://github.com/PowerShell/PowerShell/issues/2396 It "Should handle stdin redirection without error" -Pending { - $process = Start-Process sort -Wait -RedirectStandardOutput $tempFile -RedirectStandardInput $assetsFile + $process = Start-Process sort -Wait -RedirectStandardOutput $tempFile -RedirectStandardInput $assetsFile @extraArgs $dirEntry = get-childitem $tempFile $dirEntry.Length | Should -BeGreaterThan 0 } @@ -116,13 +120,31 @@ Describe "Start-Process" -Tags @("Feature") { It "Should be able to use the -WhatIf switch without performing the actual action" { $pingOutput = Join-Path $TestDrive "pingOutput.txt" - { Start-Process -Wait $pingCommand -ArgumentList $pingParam -RedirectStandardOutput $pingOutput -WhatIf -ErrorAction Stop } | Should -Not -Throw + { Start-Process -Wait $pingCommand -ArgumentList $pingParam -RedirectStandardOutput $pingOutput -WhatIf -ErrorAction Stop @extraArgs} | Should -Not -Throw $pingOutput | Should -Not -Exist } It "Should return null when using -WhatIf switch with -PassThru" { Start-Process $pingCommand -ArgumentList $pingParam -PassThru -WhatIf | Should -BeNullOrEmpty - } + } + + It 'Should run without errors when -ArgumentList is $null' { + $process = Start-Process $pingCommand -ArgumentList $null -PassThru @extraArgs + $process.Length | Should -Be 1 + $process.Id | Should -BeGreaterThan 1 + } + + It "Should run without errors when -ArgumentList is @()" { + $process = Start-Process $pingCommand -ArgumentList @() -PassThru @extraArgs + $process.Length | Should -Be 1 + $process.Id | Should -BeGreaterThan 1 + } + + It "Should run without errors when -ArgumentList is ''" { + $process = Start-Process $pingCommand -ArgumentList '' -PassThru @extraArgs + $process.Length | Should -Be 1 + $process.Id | Should -BeGreaterThan 1 + } } Describe "Start-Process tests requiring admin" -Tags "Feature","RequireAdminOnWindows" {