所以我有Powershell
script
并且我想知道如何访问它的args
使用Visual Studio
参数窗口:
这就是我尝试使用它的方式arguments
:
Write-Host "here's arg 0: $($args[0])"
但目前这返回空字符串:
here's arg 0:
所以我有Powershell
script
并且我想知道如何访问它的args
使用Visual Studio
参数窗口:
这就是我尝试使用它的方式arguments
:
Write-Host "here's arg 0: $($args[0])"
但目前这返回空字符串:
here's arg 0:
您需要关闭项目属性页面,然后打开要作为启动脚本的文件并按下F5以运行项目。
这样,您在参数脚本参数中输入的参数将被传递给脚本。请记住,参数将被传递给以空格分隔的脚本,因此如果空格是参数的一部分,请用引号将该参数括起来。
您可以在Output窗口和PowerShell Interactive Window中看到结果。
例子
有脚本:
"Number of args: $($args.Count)"
for($i=0; $i -lt $args.Count; $i++)
{
"arg[$i]: $($args[$i])"
}
将以下值设置为Script Argument:
"Some Value" "Another Value"
如果按f5,您将在输出窗口中看到以下结果:
PS C:\Example> C:\Example\Script.ps1
Number of args: 2
arg[0]: Some Value
arg[1]: Another Value
The program 'Script.ps1: PowerShell Script' has exited with code 0 (0x0).