Version Matrix

just-sysprocess

Just SysProcess

Build Status Release Status

Latest version Maven Central

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

Example

Scala 2.11 ~ 2.13

Run on Scastie: https://scastie.scala-lang.org/JvBBO4WgR3y8WN5Cd1EXMQ

import just.sysprocess._

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

val result: Either[String, List[String]] = ProcessResult.toEither(
  SysProcess.run(sysProcess)
) {
    case ProcessResult.Success(result) =>
      Right(result)

    case ProcessResult.Failure(code, error) =>
      Left(s"Failed: code: $code, ${error.mkString("\n")}")

    case ProcessResult.FailureWithNonFatal(nonFatalThrowable) =>
      Left(nonFatalThrowable.getMessage)
}
result match {
  case Right(files) =>
    println(files.mkString("Files: \n  -", "\n  -", "\n"))

  case Left(error) =>
    println(s"ERROR: ${error.toString}")
}

Scala 3 (Dotty)

Run on Scastie: https://scastie.scala-lang.org/4Nh0xTT5THKpz91F3dcy2w

import just.sysprocess._

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

  val result: Either[String, List[String]] = ProcessResult.toEither(
    SysProcess.run(sysProcess)
  ) {
      case ProcessResult.Success(result) =>
        Right(result)

      case ProcessResult.Failure(code, error) =>
        Left(s"Failed: code: $code, ${error.mkString("\n")}")

      case ProcessResult.FailureWithNonFatal(nonFatalThrowable) =>
        Left(nonFatalThrowable.getMessage)
  }
  result match {
    case Right(files) =>
      println(files.mkString("Files: \n  -", "\n  -", "\n"))
    
    case Left(error) =>
      println(s"ERROR: ${error.toString}")
  }
}