简体   繁体   中英

Powershell Is it possible to start process -wait in parallel

I tried something like this and it starts one after the other

  function start-parallel {  
    workflow work {
      start-process $exe1 -wait
      start-process $exe2 -wait
    }

    work 
  }

No, you can't simultaneously wait and not wait .

What you'll want to do is save the process objects output by Start-Process -PassThru to a variable, and then not wait until after you've kicked off all the processes:

$processes = @(
  Start-Process $exe1 -PassThru
  Start-Process $exe2 -PassThru
  # ...
)

# now wait for all of them
$null = $processes |ForEach-Object WaitForExit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM