マルチスレッドを使用してpowershellでいくつかのコードを実行する必要があります。単純なスニペットをテストしましたが、powershellコンソールで正常に動作します。ただし、cmd.exe で実行しようとすると、コードが実行されず、何が起こっているのか疑問に思ってエラーがスローされませんでしたか? あなたがこれを手伝ってくれる人なら。
以下のサンプルコード
$throttleLimit = 10
$iss = [system.management.automation.runspaces.initialsessionstate]::CreateDefault()
$Pool = [runspacefactory]::CreateRunspacePool(1, $throttleLimit, $iss, $Host)
$Pool.Open()
$ScriptBlock = {
param($id)
Start-Sleep -Seconds 2
Write-Host "Done processing ID $id"
[System.Console]::WriteLine("Done processing ID $id")
}
for ($x = 1; $x -le 40; $x++) {
$powershell = [powershell]::Create().AddScript($ScriptBlock).AddArgument($x)
$powershell.RunspacePool = $Pool
$handle = $powershell.BeginInvoke()
}
私のバッチファイルコードは次のとおりです
powershell -Command .\multiT.ps1 2>&1