1/* Title: Pure/System/process_result.scala 2 Author: Makarius 3 4Result of system process. 5*/ 6 7package isabelle 8 9final case class Process_Result( 10 rc: Int, 11 out_lines: List[String] = Nil, 12 err_lines: List[String] = Nil, 13 timeout: Boolean = false, 14 timing: Timing = Timing.zero) 15{ 16 def out: String = cat_lines(out_lines) 17 def err: String = cat_lines(err_lines) 18 def errors(errs: List[String]): Process_Result = copy(err_lines = err_lines ::: errs) 19 def error(err: String): Process_Result = errors(List(err)) 20 21 def was_timeout: Process_Result = copy(rc = 1, timeout = true) 22 23 def ok: Boolean = rc == 0 24 def interrupted: Boolean = rc == Exn.Interrupt.return_code 25 26 def check_rc(pred: Int => Boolean): Process_Result = 27 if (pred(rc)) this 28 else if (interrupted) throw Exn.Interrupt() 29 else Exn.error(err) 30 31 def check: Process_Result = check_rc(_ == 0) 32 33 def print: Process_Result = 34 { 35 Output.warning(err) 36 Output.writeln(out) 37 copy(out_lines = Nil, err_lines = Nil) 38 } 39 40 def print_stdout: Process_Result = 41 { 42 Output.warning(err, stdout = true) 43 Output.writeln(out, stdout = true) 44 copy(out_lines = Nil, err_lines = Nil) 45 } 46 47 def print_if(b: Boolean): Process_Result = if (b) print else this 48 def print_stdout_if(b: Boolean): Process_Result = if (b) print_stdout else this 49} 50