Implement goalloc.
[goaljobs.git] / goaljobs.ml
index 94843ac..9688a9c 100644 (file)
@@ -242,7 +242,7 @@ let rm_rf dir =
 let shell = ref "/bin/sh"
 
 (* Used by sh, shout, shlines to handle the script and temporary dir. *)
-let with_script ?(tmpdir = false) script f =
+let with_script ?(tmpdir = true) script f =
   let dir = if tmpdir then Some (make_tmpdir ()) else None in
   let script_file, chan =
     match dir with
@@ -403,6 +403,27 @@ let publish name fn = published_goals := (name, fn) :: !published_goals
 let get_goal name =
   try Some (List.assoc name !published_goals) with Not_found -> None
 
+let log_program_output () =
+  let filename = Filename.temp_file "goaljobslog" ".txt" in
+  let cmd = "tee " ^ quote filename in
+  let chan = open_process_out cmd in
+  let fd = descr_of_out_channel chan in
+  dup2 fd stdout;
+  dup2 fd stderr;
+  filename
+
+let mailto ?from ~subject ?(attach = []) to_ =
+  let cmd = ref (sprintf "%s -s %s" mailx (quote subject)) in
+  (match from with
+  | None -> ()
+  | Some f -> cmd := !cmd ^ " -r " ^ quote f
+  );
+  List.iter (
+    fun a -> cmd := !cmd ^ " -a " ^ quote a
+  ) attach;
+  if Sys.command !cmd <> 0 then
+    goal_failed "mailto: could not send email"
+
 let goal_file_exists filename =
   if not (file_exists filename) then (
     let msg = sprintf "file '%s' required but not found" filename in