应该有一个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
}
它打印以下内容:
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
我做错了什么?
请问可以给我 goto 和标签吗?
使用 Windows 7,我猜是 PS 2.0。该脚本至少应该在 PS 2 上运行。
使用时不添加冒号break
带有循环标签。这行:
break :outer
应该这样写:
break outer
为了进一步演示,请考虑这个简单的脚本:
:loop while ($true)
{
while ($true)
{
break :loop
}
}
执行后,它将永远运行而不会中断。然而这个脚本:
:loop while ($true)
{
while ($true)
{
break loop
}
}
因为我改变了所以应该退出break :loop
to break loop
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)