aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/scalam/m/interpretation/Interpreter.scala
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2012-10-30 21:48:46 +0100
committerJakob Odersky <jodersky@gmail.com>2012-10-30 21:48:46 +0100
commita93a86db7ad1839605448f9532ac96300785a59e (patch)
treeb45a754e99ff093b324353d2e0be412df6182d51 /src/main/scala/scalam/m/interpretation/Interpreter.scala
parent215fbe731743e8f38a3a62cb1b83ab03ae32f6b6 (diff)
downloadscalam-a93a86db7ad1839605448f9532ac96300785a59e.tar.gz
scalam-a93a86db7ad1839605448f9532ac96300785a59e.tar.bz2
scalam-a93a86db7ad1839605448f9532ac96300785a59e.zip
move interpreters to seperate package
Diffstat (limited to 'src/main/scala/scalam/m/interpretation/Interpreter.scala')
-rw-r--r--src/main/scala/scalam/m/interpretation/Interpreter.scala31
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