blob: 6c239294cd0820a17d36f4b12c05271ecdb91ed7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
package scalam.m
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 + "\n").getBytes)
inputStream.get.flush()
}
def close(): Unit = {
inputStream.get.close
}
}
|