【发布时间】:2020-02-17 07:39:03
【问题描述】:
我正试图让乔布斯工作并再次遇到问题。
编辑:意识到我需要更改作业脚本块中的每个变量以包含“使用”,所以$using:temp_cpu, $using:temp_cpu_cores, $using:temp_cpu_logical
即使使用using 修复,即使我正在等待输出文件 a) 存在并且 b) 大小为非零,但以下输出仍然随机导致空输出,但大约 1 次运行以下结果为空输出。
function test {
$temp_cpu = "$($env:TEMP)\ps_temp_cpu.txt"
$temp_cpu_cores = "$($env:TEMP)\ps_temp_cpu_cores.txt"
$temp_cpu_logical = "$($env:TEMP)\ps_temp_cpu_logical.txt"
rm -force $temp_cpu -EA silent ; rm -force $temp_cpu_cores -EA silent ; rm -force $temp_cpu_logical -EA silent
$job_cpu = Start-Job -ScriptBlock { (Get-WmiObject -Class Win32_Processor).Name > $using:temp_cpu }
$job_cpu_cores = Start-Job -ScriptBlock { (Get-WmiObject -Class Win32_Processor).NumberOfCores > $using:temp_cpu_cores }
$job_cpu_logical = Start-Job -ScriptBlock { (Get-WmiObject -Class Win32_Processor).NumberOfLogicalProcessors > $using:temp_cpu_logical }
Wait-Job $job_cpu, $job_cpu_cores, $job_cpu_logical
while (!(Test-Path $temp_cpu)) { while ((Get-Item $temp_cpu -EA silent).length -eq 0kb) { Start-Sleep -Milliseconds 500 } }
while (!(Test-Path $temp_cpu_cores)) { while ((Get-Item $temp_cpu_cores -EA silent).length -eq 0kb) { Start-Sleep -Milliseconds 500 } }
while (!(Test-Path $temp_cpu_logical)) { while ((Get-Item $temp_cpu_logical -EA silent).length -eq 0kb) { Start-Sleep -Milliseconds 500 } }
"CPU: $(cat $temp_cpu)"
"CPU Cores: $(cat $temp_cpu_cores)"
"CPU Logical: $(cat $temp_cpu_logical)"
rm -force $temp_cpu -EA silent ; rm -force $temp_cpu_cores -EA silent ; rm -force $temp_cpu_logical -EA silent
}
【问题讨论】:
-
Receive-job 获取输出。
标签: powershell parallel-processing jobs