如何知道命令何时为';在powershell中没有响应
我有一个启动命令行实用程序的powershell脚本 DacIESvcCli.exe向我发送响应,当我收到响应时,我将获取状态,可以是“正在运行”或“已完成” 我的问题是,有时电话挂断,我从未得到回应。以下脚本可以连续运行3天。 如何防止这种情况发生?如何知道命令何时为';在powershell中没有响应,powershell,Powershell,我有一个启动命令行实用程序的powershell脚本 DacIESvcCli.exe向我发送响应,当我收到响应时,我将获取状态,可以是“正在运行”或“已完成” 我的问题是,有时电话挂断,我从未得到回应。以下脚本可以连续运行3天。 如何防止这种情况发生? $myCounter = 0 while($myCounter -lt 5){ Write "start of the while counter : " $myCounter $exportResponse = C:\DAC\DacIESvc
$myCounter = 0
while($myCounter -lt 5){
Write "start of the while counter : " $myCounter
$exportResponse = C:\DAC\DacIESvcCli.exe -s "myserver.database.windows.net" -u "mylogin@myserver" -p "mypassword" -requestid 'e1e34eee-1aaa-4cc9-8c48-3a2239fe1bff' -status
$exportStatus = $exportResponse[10].split(" ")[1].toString()
Write $exportStatus
$myCounter++
}
这是输出
start of the while counter :
0
Completed
start of the while counter :
1
Completed
start of the while counter :
2
Completed
start of the while counter :
3
_
。。。它永远不会结束。这是我的脚本的一部分
检查这些cmdlet:start job wait job查看此帖子例如:谢谢我找到了如何使用您的answer@TimPost-为什么删除用户1027785的答案?从上面的评论(和评论投票)来看,这显然足以回答OP的问题。将来看到删除其他人答案的理由可能会很好。我不是想成为一个混蛋。我想知道什么时候删除答案合适。没有人删除用户1027785的答案。他只是在评论中直接回答了问题。你介意发布结果脚本吗?
param($username, $password, $serverName, $requestId)
$consecutiveFailedAttempt = 0
while( $exportStatus -ne "Completed" -and $exportStatus -ne "Failed" -and $exportStatus -ne "TooLong"){
if($exportStatus -ne "FirstRun"){
Start-Sleep -m 60000 # Wait 1 min
}
$currentNow = Get-Date
$job = Start-Job { param($s, $u, $p, $r) C:\DAC\DacIESvcCli.exe -s $s -User $u -p $p -requestid $r -status } -ArgumentList @($serverName, $username, $password, $requestId)
Wait-Job $job -Timeout 60 # if the command takes longer than 60 sec we timeout and retry
Stop-Job $job
$exportResponse = Receive-Job $job
Remove-Job $job
if($exportResponse[10]){
$exportStatus = $exportResponse[10].split(" ")[1].toString()
$consecutiveFailedAttempt = 0;
}else{
$currentNow = Get-Date
$whileMessage = "Time out we retry " + $currentNow
$whileMessage | Out-File $File -append
$exportStatus = "Unknown"
$consecutiveFailedAttempt++;
}
if($consecutiveFailedAttempt -gt 10){
$exportStatus = "TooLong"
}
}
# do wantever you want with the export status