just-sysprocess

Just SysProcess

Build Status Release Status

Latest version Maven Central

libraryDependencies += "io.kevinlee" %% "just-sysprocess" % "1.0.0"

Example

Scala 2.11 ~ 2.13

Run on Scastie: https://scastie.scala-lang.org/Kevin-Lee/1Gvwl8I3S4epu5NnoMSjdw

import just.sysprocess._

val sysProcess = SysProcess.singleSysProcess(None, "ls")

val result: Either[ProcessError, ProcessResult] = sysProcess.run()
result match {
  case Right(ProcessResult(result)) =>
    println(result.mkString("Files: \n  -", "\n  -", "\n"))
  
  case Left(ProcessError.Failure(code, error)) =>
    println(s"[ERROR] Failed: code: $code, ${error.mkString("\n")}")
  
  case Left(ProcessError.FailureWithNonFatal(nonFatalThrowable)) =>
    println(s"[ERROR] ${nonFatalThrowable.getMessage}")
}

Scala 3 (Dotty)

Run on Scastie: https://scastie.scala-lang.org/Kevin-Lee/j6jWfzr7QtqmUAyPr4TY5w

import just.sysprocess.*

@main def runApp: Unit = {
  val sysProcess = SysProcess.singleSysProcess(None, "ls")

  val result: Either[ProcessError, ProcessResult] = sysProcess.run()
  result match {
    case Right(ProcessResult(result)) =>
      println(result.mkString("Files: \n  -", "\n  -", "\n"))

    case Left(ProcessError.Failure(code, error)) =>
      println(s"[ERROR] Failed: code: $code, ${error.mkString("\n")}")

    case Left(ProcessError.FailureWithNonFatal(nonFatalThrowable)) =>
      println(s"[ERROR] ${nonFatalThrowable.getMessage}")
  }
}