0

好的,这是我正在尝试做的伪代码:

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”文件时不会踩到对方的鞋?

4

0 回答 0