我的 PowerShell 脚本之一中有此代码:
function callCommandWithArguments([String] $arg1, [String] $arg2)
{
[string]$pathToCommand = "C:\command.exe";
[Array]$arguments = "anArg", "-other", "$arg2", "$arg1";
# the real code is
# & $pathToCommand $arguments;
# but was not working, so I change it to debug
Write-Host $pathToCommand $arguments;
}
callCommandWithArguments("1", "2");
由于$arguments
数组中的参数顺序发生了变化,我希望这个输出:
C:\command.exe anArg -other 2 1
但相反,我收到一个奇怪的消息:
C:\command.exe anArg -other 1 2
我错过了一些明显的东西吗?