diff options
Diffstat (limited to 'src/main/scala/scalam/m/interpretation/Interpreter.scala')
-rw-r--r-- | src/main/scala/scalam/m/interpretation/Interpreter.scala | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/main/scala/scalam/m/interpretation/Interpreter.scala b/src/main/scala/scalam/m/interpretation/Interpreter.scala new file mode 100644 index 0000000..93411c3 --- /dev/null +++ b/src/main/scala/scalam/m/interpretation/Interpreter.scala @@ -0,0 +1,31 @@ +package scalam.m.interpretation + +import scalax.file.Path +import scala.sys.process._ +import scala.io._ +import java.io._ +import scala.concurrent._ + +class Interpreter(command: String, pwd: Path) { + private val inputStream = new SyncVar[OutputStream]; + + val process = Process(command, pwd.fileOption, "" -> "").run( + new ProcessIO( + stdin => inputStream.put(stdin), + stdout => Source.fromInputStream(stdout).getLines.foreach(println), + stderr => Source.fromInputStream(stderr).getLines.foreach(println))); + + def write(s: String): Unit = synchronized { + inputStream.get.write((s).getBytes) + inputStream.get.flush() + } + + def close(): Unit = { + inputStream.get.close + } + + def kill(): Unit = { + close() + process.destroy() + } +}
\ No newline at end of file |