Packages

  • package root
    Definition Classes
    root
  • package io
    Definition Classes
    root
  • package github
    Definition Classes
    io
  • package vigoo
    Definition Classes
    github
  • package prox

    Provides classes to work with system processes in a type safe way.

    Provides classes to work with system processes in a type safe way.

    Overview

    A system process to be started is represented by the Process case class, taking a command and optionally a list of arguments and a working directory:

    import io.github.vigoo.prox._
    import io.github.vigoo.prox.syntax._
    
    val process = Process("echo", List("Hello world"))

    To start the process, we can use the syntax.ProcessOps.start extension method, defined in syntax.ProcessOps, which creates a cats IO operation returning a RunningProcess instance.

    Use the returned value to wait for the process to exit or to send a termination signal to it:

    val program = Blocker[IO].use { blocker =>
      for {
        echo <- Process("echo", List("Hello world")).start(blocker)
        result <- echo.waitForExit()
      } yield result.exitCode
    }
    
    val exitCode = program.unsafeRunSync()

    Redirection

    The syntax.ProcessNodeInputRedirect, syntax.ProcessNodeOutputRedirect and syntax.ProcessNodeErrorRedirect classes define extension methods for processes to redirect their inpout, output and error streams. The target of redirection can be anything that has the matching type class defined for: CanBeProcessInputSource, CanBeProcessOutputTarget and CanBeProcessErrorTarget.

    The three extension methods are syntax.ProcessNodeInputRedirect.<, syntax.ProcessNodeOutputRedirect.> and syntax.ProcessNodeErrorRedirect.redirectErrorTo

    The type system guarantees that each redirection can only happen once for a process.

    Streams

    The library provides type classes to redirect to/from fs2 streams: InputStreamingSource for feeding a stream as a process' input, and OutputStreamingTarget and ErrorStreamingTarget to feed a process' output and error to fs2 pipes.

    Three special wrapper types can be used to modify how the streams are executed when the IO operation is composed:

    • Drain to run the stream with fs2.Stream.CompileOps.drain, having a result of Unit
    • ToVector to run the stream with fs2.Stream.CompileOps.toVector, having a result of Vector
    • Fold to run the stream with fs2.Stream.CompileOps.fold, having a custom fold result

    If none of the above wrappers is used, the default is to use fs2.Stream.CompileOps.drain for fs2.Sink, fs2.Stream.CompileOps.foldMonoid if the pipe's output is a cats.Monoid and fs2.Stream.CompileOps.toVector otherwise.

    Piping

    The syntax.ProcessNodeOutputRedirect class defined two extension methods for piping one process to another: syntax.ProcessNodeOutputRedirect.| for direct piping and syntax.ProcessNodeOutputRedirect.via for piping through a custom fs2 fs2.Pipe.

    The result of the piping operators is a PipedProcess, which can be used exactly as a simple process, but its syntax.ProcessOps.start method returns a tuple of RunningProcess instances.

    Definition Classes
    vigoo
  • object syntax

    Implicit classes for working with simple and piped processes

    Implicit classes for working with simple and piped processes

    All the operations are implemented for both simple Process objects and PipedProcess objects as well. Most of the operations encode information in the types of the processes as well.

    The operations are implemented by various type classes and exposed through extension methods defined in the implicit classes in this object.

    Examples

    Starting simple and piped processes:

    val echoProcess = Process("echo", List("This is an output"))
    val wordCountProcess = Process("wc", List("-w"))
    val combined = echoProcess | wordCountProcess
    
    for {
      echo1 <- Process("echo", List("Hello world")).start
      runningProcs <- combined.start
      (echo2, wordCount) = runningProcs
    } yield ()

    Redirecting input, output and error channels:

    val p1 = Process("echo", List("Hello world")) > (home / "tmp" / "out.txt")
    val p2 = Process("cat") < (home / "something")
    val p3 = Process("make") errorTo (home / "errors.log")

    Piping:

    val echoProcess = Process("echo", List("This is an output"))
    val wordCountProcess = Process("wc", List("-w"))
    val combined1 = echoProcess | wordCountProcess
    
    val customPipe: Pipe[IO, Byte, Byte] = ???
    val combined2 = echoProcess.via(customPipe).to(wordCountProcess)
    Definition Classes
    prox
  • ProcessNodeErrorRedirect
  • ProcessNodeInputRedirect
  • ProcessNodeOutputRedirect
  • ProcessOps

implicit class ProcessOps[PN <: ProcessNode[_, _, _, _, _]] extends AnyRef

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ProcessOps
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new ProcessOps(processNode: PN)

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  9. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  10. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  11. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  12. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  13. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  14. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  15. def start[F[_], RP](blocker: Blocker)(implicit contextOf: Aux[PN, F], start: Aux[F, PN, RP, _], concurrent: Concurrent[F], contextShift: ContextShift[F]): F[RP]

    Starts the process

    Starts the process

    RP

    Type encoding the RunningProcess instances

    blocker

    Execution context for the blocking stream IO

    start

    Type class implementing the process starting

    contextShift

    Context shifter to be used for the streams

    returns

    Returns the RunningProcess instances for the system processes which has been started

  16. def startHL[F[_], RPL <: HList](blocker: Blocker)(implicit contextOf: Aux[PN, F], start: Aux[F, PN, _, RPL], concurrent: Concurrent[F], contextShift: ContextShift[F]): F[RPL]

    Starts the process

    Starts the process

    RPL

    Type encoding the RunningProcess instances in a shapeless.HList

    blocker

    Execution context for the blocking stream IO

    start

    Type class implementing the process starting

    contextShift

    Context shifter to be used for the streams

    returns

    Returns the HList of RunningProcess instances for the system processes which has been started

  17. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  18. def toString(): String
    Definition Classes
    AnyRef → Any
  19. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  20. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  21. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from AnyRef

Inherited from Any

Ungrouped