src/Pure/System/isabelle_system.scala
changeset 61281 11c1bf92d61d
parent 61025 636b578bfadd
child 61282 3e578ddef85d
--- a/src/Pure/System/isabelle_system.scala	Tue Sep 29 16:58:33 2015 +0200
+++ b/src/Pure/System/isabelle_system.scala	Tue Sep 29 18:39:55 2015 +0200
@@ -8,10 +8,12 @@
 package isabelle
 
 
-import java.io.{File => JFile, IOException}
+import java.io.{File => JFile, IOException, BufferedReader, InputStreamReader}
 import java.nio.file.{Path => JPath, Files, SimpleFileVisitor, FileVisitResult}
 import java.nio.file.attribute.BasicFileAttributes
 
+import scala.collection.mutable
+
 
 object Isabelle_System
 {
@@ -58,7 +60,10 @@
       (2) ISABELLE_HOME process environment variable (e.g. inherited from running isabelle tool)
       (3) isabelle.home system property (e.g. via JVM application boot process)
   */
-  def init(isabelle_home: String = "", cygwin_root: String = ""): Unit = synchronized {
+  def init(
+      isabelle_home: String = "",
+      cygwin_root: String = "",
+      progress: Progress = Ignore_Progress): Unit = synchronized {
     if (_settings.isEmpty) {
       import scala.collection.JavaConversions._
 
@@ -114,7 +119,7 @@
             else Nil
           val cmdline =
             shell_prefix ::: List(system_home + "/bin/isabelle", "getenv", "-d", dump.toString)
-          val (output, rc) = process_output(raw_execute(null, env, true, cmdline: _*))
+          val (output, rc) = process_output(progress, raw_execute(null, env, true, cmdline: _*))
           if (rc != 0) error(output)
 
           val entries =
@@ -194,10 +199,28 @@
     proc.start
   }
 
-  private def process_output(proc: Process): (String, Int) =
+  def process_output(progress: Progress, proc: Process): (String, Int) =
   {
     proc.getOutputStream.close
-    val output = File.read_stream(proc.getInputStream)
+
+    val output =
+    {
+      val lines = new mutable.ListBuffer[String]
+
+      val stdout = new BufferedReader(new InputStreamReader(proc.getInputStream, UTF8.charset))
+      try {
+        var line = stdout.readLine
+        while (line != null) {
+          progress.echo(line)
+          lines += line
+          line = stdout.readLine
+        }
+      }
+      finally { stdout.close }
+
+      cat_lines(lines.toList)
+    }
+
     val rc =
       try { proc.waitFor }
       finally {
@@ -206,6 +229,7 @@
         proc.destroy
         Thread.interrupted
       }
+
     (output, rc)
   }
 
@@ -298,7 +322,7 @@
       if (Platform.is_windows) List(get_cygwin_root() + "\\bin\\bash.exe")
       else List("/usr/bin/env", "bash")
     val cmdline = bash ::: List("-c", "kill -" + signal + " -" + group_pid)
-    process_output(raw_execute(null, null, true, cmdline: _*))
+    process_output(Ignore_Progress, raw_execute(null, null, true, cmdline: _*))
   }
 
 
@@ -364,7 +388,7 @@
     } match {
       case Some(dir) =>
         val file = File.standard_path(dir + Path.basic(name))
-        process_output(execute(true, (List(file) ::: args.toList): _*))
+        process_output(Ignore_Progress, execute(true, (List(file) ::: args.toList): _*))
       case None => ("Unknown Isabelle tool: " + name, 2)
     }
   }