0

Okay, here's a pseudo-code of what I'm trying to do:

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
    }

  }

However, naively running the above resulted in several jobs ending with errors, because apparently "logfile.log" is being opened by another job running at the same time.

So, how do I ensure that all jobs will not step on each other's shoes when writing to the "logfile.log" file?

pepoluan
  • 6,132
  • 4
  • 46
  • 76
  • use a logfile per each server and consolidate them at the end of your scripts? – Loïc MICHEL Jul 03 '13 at 17:52
  • @Kayasax so, no way of avoiding biting the poisoned apple? :( – pepoluan Jul 04 '13 at 16:08
  • It's not clear what you're trying to accomplish here. What are the parameters in **$params** supposed to be passed to? **$OneJob** is a script block. Script blocks don't take parameters. If the idea is that the parameters will be passed to each command in the script block, that's not going to work. Please clarify. – Adi Inbar Jul 14 '13 at 02:09
  • @AdiInbar what do you mean "Script blocks don't take parameters"? Script blocks *can* and *do* take parameters if it is passed using the `-ArgumentList` parameter. See http://stackoverflow.com/a/10198451 for an example. – pepoluan Jul 16 '13 at 13:27

0 Answers0