src/Pure/System/isabelle_system.scala
changeset 34194 001321ca185c
parent 34186 b91953f894a8
child 34195 d58da36d1a30
equal deleted inserted replaced
34193:d3358b909c40 34194:001321ca185c
    40 
    40 
    41   private def process_output(proc: Process): (String, Int) =
    41   private def process_output(proc: Process): (String, Int) =
    42   {
    42   {
    43     proc.getOutputStream.close
    43     proc.getOutputStream.close
    44     val output = Source.fromInputStream(proc.getInputStream, charset).mkString
    44     val output = Source.fromInputStream(proc.getInputStream, charset).mkString
    45     val rc = proc.waitFor
    45     val rc =
       
    46       try { proc.waitFor }
       
    47       finally {
       
    48         proc.getInputStream.close
       
    49         proc.getErrorStream.close
       
    50         proc.destroy
       
    51         Thread.interrupted
       
    52       }
    46     (output, rc)
    53     (output, rc)
    47   }
    54   }
    48 }
    55 }
    49 
    56 
    50 
    57 
    85 
    92 
    86     val dump = File.createTempFile("isabelle", null)
    93     val dump = File.createTempFile("isabelle", null)
    87     try {
    94     try {
    88       val cmdline = shell_prefix :::
    95       val cmdline = shell_prefix :::
    89         List(isabelle_home + "/bin/isabelle", "getenv", "-d", dump.toString)
    96         List(isabelle_home + "/bin/isabelle", "getenv", "-d", dump.toString)
    90       val proc = Isabelle_System.raw_execute(env0, true, cmdline: _*)
    97       val (output, rc) =
    91       val (output, rc) = Isabelle_System.process_output(proc)
    98         Isabelle_System.process_output(Isabelle_System.raw_execute(env0, true, cmdline: _*))
    92       if (rc != 0) error(output)
    99       if (rc != 0) error(output)
    93 
   100 
    94       val entries =
   101       val entries =
    95         for (entry <- Source.fromFile(dump).mkString split "\0" if entry != "") yield {
   102         for (entry <- Source.fromFile(dump).mkString split "\0" if entry != "") yield {
    96           val i = entry.indexOf('=')
   103           val i = entry.indexOf('=')
   257       val file = platform_file(dir + "/" + name)
   264       val file = platform_file(dir + "/" + name)
   258       try { file.isFile && file.canRead && file.canExecute }
   265       try { file.isFile && file.canRead && file.canExecute }
   259       catch { case _: SecurityException => false }
   266       catch { case _: SecurityException => false }
   260     }) match {
   267     }) match {
   261       case Some(dir) =>
   268       case Some(dir) =>
   262         val proc = execute(true, (List(platform_path(dir + "/" + name)) ++ args): _*)
   269         Isabelle_System.process_output(
   263         Isabelle_System.process_output(proc)
   270           execute(true, (List(platform_path(dir + "/" + name)) ++ args): _*))
   264       case None => ("Unknown Isabelle tool: " + name, 2)
   271       case None => ("Unknown Isabelle tool: " + name, 2)
   265     }
   272     }
   266   }
   273   }
   267 
   274 
   268 
   275 
   283 
   290 
   284   def fifo_stream(fifo: String): BufferedInputStream =
   291   def fifo_stream(fifo: String): BufferedInputStream =
   285   {
   292   {
   286     // blocks until writer is ready
   293     // blocks until writer is ready
   287     val stream =
   294     val stream =
   288       if (Platform.is_windows) execute(false, "cat", fifo).getInputStream
   295       if (Platform.is_windows) {
       
   296         val proc = execute(false, "cat", fifo)
       
   297         proc.getOutputStream.close
       
   298         proc.getErrorStream.close
       
   299         proc.getInputStream
       
   300       }
   289       else new FileInputStream(fifo)
   301       else new FileInputStream(fifo)
   290     new BufferedInputStream(stream)
   302     new BufferedInputStream(stream)
   291   }
   303   }
   292 
   304 
   293 
   305