gre / playcli Goto Github PK
View Code? Open in Web Editor NEWPlay Framework Iteratees + UNIX pipe library
Play Framework Iteratees + UNIX pipe library
Example: CLI.pipe("convert - png:-")
Bug: the command is never terminated. stdin is written, but nothing is read from the command which is not responding.
Tail as an enumerator keeps waiting and does not go through grep. Below is a sample code to reproduce the issue.
val file = args(0)
val pattern = args(1)
val tail = CLI.enumerate(Seq("tail", "-f", file))
val grep = CLI.pipe(Seq("grep", pattern))
val printlnIteratee = Iteratee.foreach[Array[Byte]](s => print(new String(s)))
tail &> grep |>>> printlnIteratee
import collection.immutable.StringOps
import play.api.libs.concurrent.Promise.timeout
import concurrent.{Await}
import concurrent.duration.Duration
val maxDuration = Duration.Inf
val stringToBytes = (str: StringOps) => str.map(_.toByte).toArray
val bytesJoinConsumer = Iteratee.fold[Array[Byte], Array[Byte]](Array[Byte]())((a, b) => a++b)
val nbOfLines = 3
val line = stringToBytes("hello\n")
val enum = Enumerator.generateM[Array[Byte]] {
timeout(Some(line), 5)
}
val pipe = CLI.pipe(Seq("head", "-n", nbOfLines.toString), 10)
val result: Array[Byte] = Await.result(enum &> pipe |>>> bytesJoinConsumer, maxDuration)
println(result.map(_.toChar).mkString)
It could be a callback:
CLI.pipe("myCommand", (exitCode) => { doSomethingWith(exitCode) } )
I've started to implement it like this:
(pipe example)
runProcess(command) map { case (process, stdin, stdout, stderr) =>
...
} getOrElse(Future.successful(Error("CLI failed", Input.Empty)))
But it's maybe not the good way.
because README says
"fr.greweb" %% "playcli" % "0.12"
CLI.pipe current implementation seems to lock in some case (command are not closed and nothing is streamed anymore).
Example for (1):
import concurrent.ExecutionContext.Implicits.global
import concurrent.{Future, Await}
import concurrent.duration.Duration
import play.api.libs.iteratee._
import cli.CLI
val enum = Enumerator("test".map(_.toByte).toArray)
val cat = CLI.pipe("cat")
val all = enum &> cat &> cat &> cat |>>> Iteratee.consume[Array[Byte]]()
concurrent.Await.result(all, Duration("2 s")).map(_.toChar).mkString
Exemple:
val addEchoToOgg = CLI.pipe("sox -t ogg - -t ogg - echo 0.5 0.7 60 1")
val radioStream = proxyBroadcast("http://radio.hbr1.com:19800/ambient.ogg")
val (radioStreamWithEcho, _) = Concurrent.broadcast(radioStream &> addEchoToOgg)
def radio = Action(Ok.stream(radioStreamWithEcho).withHeaders(CONTENT_TYPE -> "audio/ogg"))
Today we are blocking thread when reading InputStream,
it would be great if we could find a non blocking Process IO lib
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.