Created
April 27, 2019 18:08
-
-
Save mprihoda/d50c8322eb3b9fb36290c8b84d9f0027 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import $ivy.`com.zaxxer:nuprocess:1.2.4`, com.zaxxer.nuprocess._ | |
import scala.collection.JavaConverters._ | |
import java.nio.ByteBuffer | |
import scala.concurrent.{Future, Promise} | |
class ProcessHandler extends NuAbstractProcessHandler { | |
private var nuProcess: NuProcess = null | |
override def onStart(nuProcess: NuProcess): Unit = { | |
this.nuProcess = nuProcess | |
} | |
override def onStdout(buffer: ByteBuffer, closed: Boolean): Unit = { | |
if (!closed) { | |
val bytes = new Array[Byte](buffer.remaining()) | |
buffer.get(bytes); | |
Console.println(new String(bytes)); | |
nuProcess.closeStdin(true); | |
} | |
} | |
} | |
val pb = new NuProcessBuilder(List("/bin/cat").asJava) | |
pb.setProcessListener(new ProcessHandler) | |
val process = pb.start() | |
process.writeStdin(ByteBuffer.wrap("Hello World!".getBytes("UTF-8"))) | |
process.waitFor(0, java.util.concurrent.TimeUnit.SECONDS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment