質問

I have two external processes to be run sequentially:

  val antProc = Process(Seq(antBatch","everythingNoJunit"), new File(scriptDir))

  val bossProc = Process(Seq(bossBatch,"-DcreateConnectionPools=true"))

  val f: Future[Process] = Future {
    println("Run ant...")
    antProc.run
  }
  f onSuccess {
    case proc => {
      println("Run boss...")
      bossProc.run
    }
  }

The result is:

  Run ant...

  Process finished with exit code 0

How do I run antProc until completion, then bossProc?

The following method seems to achieve the purpose. However, it's not a Future approach.

    antProc.!<
    bossProc.!<
役に立ちましたか?

解決

You should be able to do something like this:

val antProc = Process(Seq(antBatch,"everythingNoJunit"), new File(scriptDir))
val bossProc = Process(Seq(bossBatch,"-DcreateConnectionPools=true"))
val antFut: Future[Process] = Future {      
  antProc.run
}
val bossFut: Future[Process] = Future {      
  bossProc.run
}
val aggFut = for{
  antRes <- antFut
  bossRes <- bossFut
} yield (antRes, bossRes)

aggFut onComplete{
  case tr => println(tr)
}

The result of the aggFut will be a tuple consisting of the ant result and the boss result.

Also, be sure your vm that is running this is not exiting before the async callbacks can occur. If your execution context contains daemon threads then it might exit before completion.

Now if you want bossProc to run after antProc, the code would look like this

val antProc = Process(Seq(antBatch,"everythingNoJunit"), new File(scriptDir))
val bossProc = Process(Seq(bossBatch,"-DcreateConnectionPools=true"))
val antFut: Future[Process] = Future {      
  antProc.run
}
val aggFut = for{
  antRes <- antFut
  bossRes <- Future {bossProc.run}
} yield (antRes, bossRes)

aggFut onComplete{
  case tr => println(tr)
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top