You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Start-Process -ArgumentList should accept an empty array / the null collection and interpret that as "no arguments to pass" #4520
Committee-ReviewedPS-Committee has reviewed this and made a decisionIssue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-FixedThe issue is fixed.WG-Cmdletsgeneral cmdlet issues
-ArgumentList (-Args) currently requires that a non-empty array be passed, which is inconvenient in scenarios where you want to pass arguments through, whether any were specified or not, such as via $Args.
An empty array or a null collection ([System.Management.Automation.Internal.AutomationNull]::Value) should be accepted and should be interpreted as "no arguments to pass".
Currently, passing $Args through in a function is cumbersome; imagine a function wpsh whose purpose is to invoke a Windows PowerShell window from PowerShell Core, with any arguments passed through:
functionwpsh {
# Pass all arguments through. # To do this in a single Start-Process call, you need a cumbersome workaround# via an aux. hashtable and splatting.# Ideally, # Start-Process (Get-Command powershell.exe).Path -Args $Args # should work directly.$htArgs=if ($Args.Count) { @{ Args=$Args } } else { @{} }
Start-Process (Get-Commandpowershell.exe).Path @htArgs
}
Steps to reproduce
# Or: [System.Management.Automation.Internal.AutomationNull]::Value, such as produced by `& {}`$arguments=@()
Start-Process code -Args $arguments
Expected behavior
code (the Visual Studio CLI, if installed) should open / activate, with no arguments being passed.
Actual behavior
Invocation fails with the following error message:
Start-Process : Cannot validate argument on parameter 'ArgumentList'.
The argument is null, empty, or an element of the argument collection contains a null value.
Supply a collection that does not contain any null values and then try the command again.
Environment data
PowerShell Core v6.0.0-beta.5 on macOS 10.12.6
PowerShell Core v6.0.0-beta.5 on Ubuntu 16.04.3 LTS
PowerShell Core v6.0.0-beta.5 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
Windows PowerShell v5.1.15063.483 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
changed the title [-]Start-Process -ArgumentList should accept empty arrays / the null collection and interpret that as "no arguments to pass"[/-][+]Start-Process -ArgumentList should accept an empty array / the null collection and interpret that as "no arguments to pass"[/+]on Aug 7, 2017
Ilya (@iSazonov): It is primarily about passing $Args through, though allowing empty arrays can also help with dynamically constructed parameter lists; I've added an example to the initial post, based on this real-world code.
Re ZSkycat (@ZSkycat)'s issue: it is the same issue (and Windows PowerShell and PowerShell Core are therefore equally affected): if $cmd[1..$cmd.Length] evaluates to $null - i.e., if the PowerShell instance was originally invoked without any arguments - binding to -ArgumentList breaks.
Windows PowerShell support -ArgumentList equal $null
Windows PowerShell And PowerShell Core will throw an error
Start-Process : Cannot validate argument on parameter 'ArgumentList'. The argument is null, empty, or an element of the
argument collection contains a null value. Supply a collection that does not contain any null values and then try the
command again.
Yes, it is the same issue, but Windows PowerShell also doesn't support an empty array / $null-ArgumentList value: try Start-Process notepad -ArgumentList $null
As an aside: Unfortunately, the way Start-Process currently works may require additional, embedded quoting to pass arguments through.
For instance, your function would fail if the session had been invoked with something like powershell -noexit -file "C:\Users\jdoe\t 1.ps1", due to the space in the filename - see #5576
Committee-ReviewedPS-Committee has reviewed this and made a decisionIssue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-FixedThe issue is fixed.WG-Cmdletsgeneral cmdlet issues
Activity
[-]Start-Process -ArgumentList should accept empty arrays / the null collection and interpret that as "no arguments to pass"[/-][+]Start-Process -ArgumentList should accept an empty array / the null collection and interpret that as "no arguments to pass"[/+]iSazonov commentedon Aug 8, 2017
Is the main motivation a dynamic construction of the parameter list? Any samples?
mklement0 commentedon Aug 8, 2017
Ilya (@iSazonov): It is primarily about passing
$Argsthrough, though allowing empty arrays can also help with dynamically constructed parameter lists; I've added an example to the initial post, based on this real-world code.ZSkycat commentedon Nov 29, 2017
I also encountered this problem.
my code
can work in Windows Powershellcan not work in Powershell CoreIlya (@iSazonov)
iSazonov commentedon Nov 29, 2017
ZSkycat (@ZSkycat) It seem is another issue. Please open Issue-Question.
iSazonov commentedon Nov 29, 2017
Steve Lee (@SteveL-MSFT) Can you approve Michael Klement (@mklement0) request change?
mklement0 commentedon Nov 29, 2017
Ilya (@iSazonov):
Thanks.
Re ZSkycat (@ZSkycat)'s issue: it is the same issue (and Windows PowerShell and PowerShell Core are therefore equally affected): if
$cmd[1..$cmd.Length]evaluates to$null- i.e., if the PowerShell instance was originally invoked without any arguments - binding to-ArgumentListbreaks.ZSkycat commentedon Nov 29, 2017
Ilya (@iSazonov)
This is the same issue. As Michael Klement (@mklement0) said
Windows PowerShell support -ArgumentList equal $nullWindows PowerShellAndPowerShell Corewill throw an errormklement0 commentedon Nov 29, 2017
ZSkycat (@ZSkycat):
Yes, it is the same issue, but Windows PowerShell also doesn't support an empty array /
$null-ArgumentListvalue: tryStart-Process notepad -ArgumentList $nullAs an aside: Unfortunately, the way
Start-Processcurrently works may require additional, embedded quoting to pass arguments through.For instance, your function would fail if the session had been invoked with something like
powershell -noexit -file "C:\Users\jdoe\t 1.ps1", due to the space in the filename - see #5576ZSkycat commentedon Nov 29, 2017
Michael Klement (@mklement0)
I try it, you are right.
3 remaining items
SteveL-MSFT commentedon Mar 17, 2018
Bruce Payette (@BrucePay) do you want to submit a PR for this?
Fix for #4520 '-ArgumentList should accept @() or $null' (#6597)
Fix for PowerShell#4520 '-ArgumentList should accept @() or $null' (P…