0

実行されているが出力を返さないこのスクリプトがあります。

function code-Build-RepoWeb
{
     $job = Start-Job { code-Build-Component RepoWeb; Start-Sleep -seconds 5 }

     Register-ObjectEvent $job -EventName StateChanged `
    -SourceIdentifier JobStateChanged `
    -Action {$jobInfo = Receive-Job -Keep $Sender; Write-Host $jobInfo }
 }

私はPowershellの専門家ではないので、質問する前にいくつかのドキュメントを読んでください。

ありがとう

4

1 に答える 1

4

イベントに登録する必要はありません。登録方法は次のとおりです。

 Start-Job { ... } | Wait-Job | Receive-Job -Keep

ノンブロッキングコマンドが必要な場合。これにより、ジョブの結果を保持するグローバル変数が作成されます。

$job = Start-Job { Start-Sleep -Seconds 5; 1..5 }

$null = Register-ObjectEvent $job -EventName StateChanged -SourceIdentifier JobEnd -Action {

    if($sender.State -eq 'Completed')
    {
        $global:jobInfo = Receive-Job $job        
    } 
}   

$jobInfo
于 2012-09-05T20:46:38.517 に答える