Returns an Iteratee for piping a command which consumes input.
Returns an Iteratee for piping a command which consumes input.
This method is useful for side effect commands.
the UNIX command
the time in milliseconds to wait before the process to terminate when consume is done
an Iteratee[Array[Byte], Int]
which consumes data and returns the exitValue of the command when done.
enumerator |>>> CLI.consume("aSideEffectCommand")
Returns an Enumerator from a command which generates output - nothing is sent to the CLI input.
Returns an Enumerator from a command which generates output - nothing is sent to the CLI input.
the UNIX command
the time in milliseconds to wait before the process to terminate when enumerate is done
an play.api.libs.iteratee.Enumerator from this command which generate output. (immutable)
CLI.enumerate("find .")
Returns an Enumeratee for piping a command which consumes input and generates output.
Returns an Enumeratee for piping a command which consumes input and generates output.
the UNIX command
the time in milliseconds to wait before the process to terminate when pipe is done
an play.api.libs.iteratee.Enumeratee from the pipe of this command which consumes input and generates output. (immutable)
// Add an echo to an ogg audio stream. oggStream &> CLI.pipe("sox -t ogg - -t ogg - echo 0.5 0.7 60 1")
CLI defines helpers to deal with UNIX command with Play Framework iteratees.
Overview
Depending on your needs, you can Enumerate / Pipe / Consume an UNIX command:
CLI.enumerate is a way to create a stream from a command which generates output (it creates an Enumerator[Array[Byte]] )
CLI.pipe is a way to pipe a command which consumes input and generates output (it creates an Enumeratee[Array[Byte],Array[Byte]])
CLI.consume creates a process which consumes a stream - useful for side effect commands (it creates an Iteratee[Array[Byte],Int])
Process
CLI uses scala.sys.process and create a Process instance for each UNIX command.
A CLI process terminates when:
CLI still waits for the Process to terminate by asking the exit code (via
Process.exitCode()
). If the process is never ending during this phase, it will be killed whenterminateTimeout
is reached.PS: Thanks to implicits, you can simply give a String or a Seq to give the CLI.* functions a
ProcessBuilder
.Mutability
enumerate and pipe are immutable, in other words, re-usable (each result can be stored in a val and applied multiple times). A new process is created for each re-use.
consume is mutable, it should not be used multiple times: it targets side effect command.
Logs
A "CLI" logger (logback) is used to log different information in different log levels:
0.1
PlayCLI-examples on Github
PlayCLI on Github