PowerShell:如何从多个作业写入文件?

时间:2013-07-03 16:07:40

标签: parallel-processing powershell-v2.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_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”文件时,如何确保所有作业不会互相踩踏?

0 个答案:

没有答案