我试图通过两种不同的方式从另一个作业中执行作业,但是在第一种情况下,我遇到错误,第二种-不要从包装的作业中检索输出。
这是我的代码:
变种1:
ToAppointments
变种2:
$joba = {
param(
$st
)
$st | Write-Output
return $st
}
$jobb = {
param(
$strng,
$ja
)
"Trying to execute joba with $strng parameter..." | Write-Output
Start-Job -Name JA $ja -ArgumentList $strng
Receive-Job -Name $ja
}
$quack = "woof"
$result = Start-Job -Name JB $jobb -ArgumentList $quack
Receive-Job JB
UPD 1 (情况1的错误消息):
$jobb = {
param(
$strng
)
$joba = {
param(
$st
)
$st | Write-Output
return $st
}
"Trying to execute joba with $strng parameter..." | Write-Output
$ja = Start-Job -Name JA $joba -ArgumentList $strng
Receive-Job -Job $ja
}
$quack = "woof"
$result = Start-Job -Name JB $jobb -ArgumentList $quack
Receive-Job JB
答案 0 :(得分:1)
嗨,我认为您必须检查此链接,它是关于如何等待工作的说法:
我想这个例子可以帮助您:
$jobb = {
param($strng,$ja)
# $strng |Write-Output
# $ja | Write-Output
$joba = {
param($st)
Write-Host $st
return $st
}
Write-Host "Trying to execute joba with $strng parameter..."
$myRunJobA = Start-Job -Name:"JA" -ArgumentList:@($strng) -ScriptBlock:$joba
# $myRunJobA
$resultJobA = Receive-Job -Job:$myRunJobA -Wait
# Write-Host $myRunJobA
}
$quack = "woof"
$myRunJobB = Start-Job -Name:"JB" -ArgumentList:@($quack) -ScriptBlock:$jobb
$resultJobB = Receive-Job -Job:$myRunJobB -Wait