curiousengineer
curiousengineer

Reputation: 2607

Using scala.sys.process with Future

I am trying to execute something like this

scala> import scala.sys.process._

scala> Process("cat temp.txt")!

I will be doing this say in a Play Framework REST handler. I want this to return a future object so that I can map/flatMap on it and do further processing when the shell is done executing. How do I do that?

Upvotes: 0

Views: 364

Answers (1)

jwvh
jwvh

Reputation: 51271

I think all you need is this.

import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import scala.sys.process._

val fs = Future("cat temp.txt".!!)  // Future[String] = Future(<not completed>)

The file contents becomes one long string but you can split() it in the map() operation.

Upvotes: 1

Related Questions