【问题标题】:Powershell wait-job gives error one or more jobs are blocked waiting for user interactionPowershell 等待作业给出错误一个或多个作业被阻止等待用户交互
【发布时间】:2021-11-11 22:00:15
【问题描述】:

我有以下命令,$a 有 20 个 URL:

$a = @('http://10.10.10.101/Login.aspx',
'http://10.10.10.101/user/customers')

$startFulltime = (Get-Date)
foreach($a1 in $a){
    start-job -ArgumentList  $a1 -ScriptBlock{
        param($a1) 
        Invoke-WebRequest $a1 -Method post -DisableKeepAlive -UseBasicParsing 
        -ArgumentList $a1
        
}}
Get-Job | Wait-Job

克服错误:

Wait-Job : The Wait-Job cmdlet cannot finish working, because one or more jobs are blocked waiting for user interaction.  Process interactive job 
output by using the Receive-Job cmdlet, and then try again.
At line:13 char:11
+ Get-Job | Wait-Job
+           ~~~~~~~~
    + CategoryInfo          : Deadlock detected: (System.Manageme...n.PSRemotingJob:PSRemotingJob) [Wait-Job], ArgumentException
    + FullyQualifiedErrorId : BlockedJobsDeadlockWithWaitJob,Microsoft.PowerShell.Commands.WaitJobCommand

参考链接:input objects in powershell jobs

请帮我解决错误,谢谢!

【问题讨论】:

  • 首先在没有作业的情况下运行Invoke-WebRequest,看看是哪一个导致了问题。

标签: powershell command-line-interface


【解决方案1】:

您的代码唯一明显的问题(可能是发布工件)是在您的 Start-Job 脚本块中存在第二个无关的 -ArgumentList $a1 - 但这会导致不同的错误,尽管可能会被该错误抢占你得到了。


这听起来像您的一项工作意外提示用户输入,正如错误消息所暗示的那样。

使用Receive-Job(如错误消息中所建议的那样)会将交互式提示带到前台,让您可以查看并回复它们。

这应该可以帮助您诊断导致问题的工作以及原因;这是一个简化的例子:

# Start a job with a command that asks the user for interactive input
# (which isn't a good idea).
$job = Start-Job { Read-Host 'Enter something' }

# !! Error, because the job is waiting for interactive user input.
$job | Wait-Job

# OK - Receive-Job "foregrounds" the Read-Host prompt.
# Once you respond to it, the job finishes
# (and is automatically removed here, thanks to -Wait -AutoRemoveJob).
$job | Receive-Job -Wait -AutoRemoveJob

【讨论】:

    猜你喜欢
    • 2022-01-07
    • 2012-03-28
    • 2021-06-16
    • 2020-02-16
    • 2022-11-28
    • 2021-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多