Created
December 7, 2016 00:44
-
-
Save fiadliel/f25bd082908c8785fefe953efae6a672 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 fs2._ | |
case class ProcessState(exitValue: Task[Int], | |
output: Stream[Task, Byte], | |
input: Sink[Task, Byte], | |
error: Stream[Task, Byte]) | |
object RunProgram { | |
val waitThreadStrategy = Strategy.fromCachedDaemonPool("wait-threads") | |
def runProgram(workingDirectory: Path, args: String*)(implicit S: Strategy): ProcessState = { | |
val pb = new ProcessBuilder(args: _*).directory(workingDirectory.toFile) | |
val process = pb.start() | |
val inStream = | |
io.readInputStreamAsync(Task.delay(process.getInputStream), 1024) | |
val outStream = io.writeOutputStream(Task.delay(process.getOutputStream)) | |
val errStream = | |
io.readInputStreamAsync(Task.delay(process.getErrorStream), 1024) | |
val result = Task(process.waitFor)(waitThreadStrategy) | |
ProcessState(result, inStream, outStream, errStream) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment