I have a function that looks something like this:
function global:Test-Multi {
Param([string]$Suite)
& perl -S "$Suite\runall.pl" -procs:$env:NUMBER_OF_PROCESSORS
}
I would like to allow the user to specify more parameters to Test-Multi and pass them directly to the underlying legacy perl script.
Does powershell provide a mechanism to allow additional variadic behavior for this purpose?
After seeing your comment, option 3 sounds like exactly what you want.
You have a few options:
Use $args
(credit to hjpotter92's answer )
Explicitly define your additional parameters, then parse them all in your function to add them to your perl call.
Use a single parameter with theValueFromRemainingArguments
argument , eg
function global:Test-Multi { Param( [string]$Suite, [parameter(ValueFromRemainingArguments = $true)] [string[]]$Passthrough ) & perl -S "$Suite\\runall.pl" -procs:$env:NUMBER_OF_PROCESSORS @Passthrough }
我不确定您希望实现什么,但是可以在函数内部可用的$args
变量中访问传递给函数的$args
。
$args
is not going to pass through arguments correctly. if you want the arguments to remain as separate arguments, you should use @args
instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.