SHARE
TWEET

Untitled

a guest Apr 20th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sealed trait ResultLine {
  2.     def line: String
  3. }
  4.  
  5. final case class Out(line: String) extends ResultLine {
  6.     override def toString: String = s"OUT: $line\n"
  7. }
  8.  
  9. final case class Err(line: String) extends ResultLine {
  10.     override def toString: String = s"ERR: $line\n"
  11. }
  12.  
  13. final case class ProcessResult(output: Seq[ResultLine], exit: Int) 
  14.  
  15.  
  16. private def executeProcess(cmd: String, parameters: Seq[String]): ProcessResult = {
  17.   import scala.sys.process._
  18.   val results = new ConcurrentLinkedQueue[ResultLine]
  19.  
  20.   val status = Process(cmd, parameters).run(ProcessLogger(
  21.     out ⇒ results.add(Out(out)),
  22.     err ⇒ results.add(Err(err))
  23.   )).exitValue()
  24.  
  25.   val builder = Seq.newBuilder[ResultLine]
  26.   while(!results.isEmpty) {
  27.     builder += results.poll()
  28.   }
  29.  
  30.   ProcessResult(builder.result(), status)
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top