Parallel processing PowerShell:如何从多个作业写入文件?
好的,这是我要做的一个伪代码:Parallel processing PowerShell:如何从多个作业写入文件?,parallel-processing,powershell-2.0,jobs,Parallel Processing,Powershell 2.0,Jobs,好的,这是我要做的一个伪代码: Function DoThings() { $OneJob = { ### things... # I want to capture the STDOUT *and* STDERR of these three commands A_Command >> "logfile.log" 2>&1 B_Command >> "logfile.log" 2>&1 C_Com
Function DoThings() {
$OneJob = {
### things...
# I want to capture the STDOUT *and* STDERR of these three commands
A_Command >> "logfile.log" 2>&1
B_Command >> "logfile.log" 2>&1
C_Command >> "logfile.log" 2>&1
}
$params = @{ }
For ($i=1; $i -lt 100; $i++) {
### Manipulate $params here
Start-Job $OneJob -ArgumentList $params
}
}
然而,天真地运行上述操作会导致多个作业以错误结束,因为显然“logfile.log”正在被同时运行的另一个作业打开
那么,我如何确保所有作业在写入“logfile.log”文件时不会踩到对方的鞋子?在每台服务器上使用一个日志文件,并在脚本结束时合并它们?@Kayasax因此,没有办法避免咬到中毒的苹果:(不清楚您在这里要完成什么。$params中的参数应该传递给什么?$OneJob是一个脚本块。脚本块不接受参数。如果您的想法是将参数传递给脚本块中的每个命令,那将不起作用。请澄清。@adInbar您的意思是什么“脚本块不接受参数”?如果使用
-ArgumentList
参数传递,脚本块可以也确实接受参数。有关示例,请参阅。