Packages

package command

Ordering
  1. Alphabetic
Visibility
  1. Public
  2. Protected

Type Members

  1. class Command extends AnyRef
  2. case class CommandOutput(stdout: Reader[Buf], stderr: Reader[Buf]) extends Product with Serializable

    The output of a shell command.

    The output of a shell command.

    stdout

    A com.twitter.io.Reader representing what is written to stdout by the shell command. Each Buf is a line of output from the command. If the command exits with a non zero return code, the final Reader#read() will return a failed com.twitter.util.Future with a NonZeroReturnCode exception. If the shell command completes successfully the final read will return a None

    stderr

    A Reader with the stderr from the shell command. The final read on stderr will always return a None, even if the command exited with a nonzero return code.

  3. case class NonZeroReturnCode(command: Seq[String], code: Int, stdErr: Reader[Buf]) extends Exception with Product with Serializable

    The exception thrown when the command returns with a nonzero return code.

    The exception thrown when the command returns with a nonzero return code.

    code

    The actual return code from the command

    stdErr

    A Reader with the stderr from the command. Note that if the stderr has already been consumed, then this Reader will only contain the portion of the stderr, that has not yet been consumed.

Value Members

  1. object Command extends Command

    A utility to allow for processing the outout from an external process in a streaming manner.

    A utility to allow for processing the outout from an external process in a streaming manner. When Command.run is called, a CommandOutput is returned, which provides a com.twitter.io.Reader interface to both the stdout and stderr of the external process.

    Example usage:

    // Run a shell command and log the output as it shows up, and then discards the output
    
    val commandOutput: CommandOutput = Command.run(Seq("./slow-shell-command.sh")
    val logged: Reader[Unit] = commandOutput.stdout.map {
     case Buf.Utf8(str) => info(s"stdout: $str")
    }
    Await.result(Reader.readAllLines(logged).onFailure {
     case NonZeroReturnCode(_, code, stderr) =>
       val errors = stderr.map {
         case Buf.Utf8(str) => str
       }
       error(s"failure: $code")
       errors.foreach(errLine => error(s"stderr: $errLine")
    })
  2. object CommandOutput extends Serializable

Ungrouped