Nick
Nick

Reputation: 1875

Start a shell script from scala Build

I've got a build step in my Build.scala that runs a shell script. However, when it runs the shell script the sbt console does not show the output from the shell script, and the sbt prompt just stops and does nothing.

I would like the shell script to be started in the background, but I would also like it's output to be shown on the console. Here's what I'm doing now:

  val startHostAndAppTask = startHostAndApp <<= dist map {d =>
      file("target/akkesb").delete()

      println("copying over akkesb distribution")
      FileUtils.copyDirectory(file("../../../target/akkesb"), file("target/akkesb"))
      file("target/akkesb/akkesb_startup.sh").setExecutable(true)
      file("target/akkesb/bin/start").setExecutable(true)

      println("copying akkesb.conf into akkesb disribution")
      IO.copyFile(file("akkesb.conf"), file("target/akkesb/akkesb.conf"))

      println("About to start akkesb")
      println( Process("sh", Seq("target/akkesb/akkesb_startup.sh", "&")).!!)

      println("starting this app")
      run
      d
    }

Upvotes: 1

Views: 1091

Answers (1)

0__
0__

Reputation: 67330

Have you looked at the API of ProcessBuilder. The !! method says:

Starts the process represented by this builder, blocks until it exits, and returns the output as a String.

(My emphasis). I think you will want something like

import sys.process._
val pb = Seq("sh", "target/akkesb/akkesb_startup.sh", "&") #> Console.out
val p  = pb.run()
// future { blocking { println(p.exitValue()) }}

Upvotes: 1

Related Questions