Answers for "process method in scala"

C#
0

process method in scala

import scala.sys.process._

// An overly complex way of computing size of a compressed file
def gzFileSize(name: String) = {
  val cat = Seq("zcat", name)
  var count = 0
  def byteCounter(input: java.io.InputStream) = {
    while(input.read() != -1) count += 1
    input.close()
  }
  val p = cat run new ProcessIO(_.close(), byteCounter, _.close())
  p.exitValue()
  count
}

// This "fire-and-forgets" the method, which can be lazily read through
// a LazyList[String], and accumulates all errors on a StringBuffer
def sourceFilesAt(baseDir: String): (LazyList[String], StringBuffer) = {
  val buffer = new StringBuffer()
  val cmd = Seq("find", baseDir, "-name", "*.scala", "-type", "f")
  val lazyLines = cmd lazyLines_! ProcessLogger(buffer append _)
  (lazyLines, buffer)
}
Posted by: Guest on August-23-2021
0

process method in scala

import java.io.File
import java.net.URL
import scala.sys.process._
new URL("http://www.scala-lang.org/") #> new File("scala-lang.html") !
Posted by: Guest on August-23-2021

C# Answers by Framework

Browse Popular Code Answers by Language