我有一个旧命令foo
,它接受任意多个(同名)输入参数,每个参数都以 为前缀--input
。从cmd.exe
,我可以运行:
C:\> foo --input "first" --input "second" --input "third" file.dat
并使用三个输入值来处理file.dat
。
我正在尝试foo
从 Powershell 脚本中调用,在其中我可以计算出一个具有可能等同于这些常量值的值/类型的数组。
$my_args = @(
"first",
"second",
"third"
)
我希望能够调用 foo ,以便--include
<value>
为 中的每个项目重复参数$my_args
。我可以使用:
foo --input $my_args[0] --input $my_args[1] --input $my_args[2] filename.dat
但如果包含的项数不正好是 3,则此方法无效$my_args
。有什么简洁的 Powershell 语法可以实现此目的吗?