-
-
Save mpkocher/7f7ca44516bb6cf42353283e04db93b6 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:2.0.0`, 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