ygo*_*goe 8 powershell loops break
break
PowerShell中应该有一个命令可以通过分配标签来退出嵌套循环.只是它不起作用.这是我的代码:
$timestampServers = @(
"http://timestamp.verisign.com/scripts/timstamp.dll",
"http://timestamp.comodoca.com/authenticode",
"http://timestamp.globalsign.com/scripts/timstamp.dll",
"http://www.startssl.com/timestamp"
)
:outer for ($retry = 2; $retry -gt 0; $retry--)
{
Write-Host retry $retry
foreach ($timestampServer in $timestampServers)
{
Write-Host timestampServer $timestampServer
& $signtoolBin sign /f $keyFile /p "$password" /t $timestampServer $file
if ($?)
{
Write-Host OK
break :outer
}
}
}
if ($retry -eq 0)
{
WaitError "Digitally signing failed"
exit 1
}
Run Code Online (Sandbox Code Playgroud)
它打印以下内容:
retry 2
timestampServer http://timestamp.verisign.com/scripts/timstamp.dll
Done Adding Additional Store
Successfully signed and timestamped: C:\myfile.dll
OK
retry 1
timestampServer http://timestamp.verisign.com/scripts/timstamp.dll
Done Adding Additional Store
Successfully signed and timestamped: C:\myfile.dll
OK
ERROR: Digitally signing failed
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
我可以带goto和标签吗?
使用Windows 7,我猜PS 2.0.该脚本应该至少在PS 2上运行.
iCo*_*dez 23
使用break
循环标签时不添加冒号.这一行:
break :outer
Run Code Online (Sandbox Code Playgroud)
应该这样写:
break outer
Run Code Online (Sandbox Code Playgroud)
有关进一步演示,请考虑以下简单脚本:
:loop while ($true)
{
while ($true)
{
break :loop
}
}
Run Code Online (Sandbox Code Playgroud)
执行时,它将永远运行而不会中断.但是这个脚本:
:loop while ($true)
{
while ($true)
{
break loop
}
}
Run Code Online (Sandbox Code Playgroud)
应该退出,因为我改变break :loop
了break loop
.
归档时间: |
|
查看次数: |
14567 次 |
最近记录: |