File: shell_uq.ml

package info (click to toggle)
ocamlnet 4.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 51,764 kB
  • ctags: 16,446
  • sloc: ml: 148,419; ansic: 10,989; sh: 1,885; makefile: 1,355
file content (43 lines) | stat: -rw-r--r-- 1,070 bytes parent folder | download | duplicates (8)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
(* $Id: shell_uq.ml 50 2004-10-03 17:06:28Z gerd $ *)

open Shell_sys
open Uq_engines

class type ['t] job_handler_engine_type = object
  inherit ['t] engine
  method job : Shell_sys.job
  method job_instance : Shell_sys.job_instance
end


class call_engine ?ignore_error_code ?mode ?stdin ?stdout ?stderr cmds ues =
  let (job, fdlist) = Shell.setup_job ?stdin ?stdout ?stderr cmds in
  let ji = run_job ?mode job in
  let close_fdlist() = List.iter Unix.close fdlist in
  let eng = new job_engine ues ji in
object(self)
  inherit
    [unit, job_status] map_engine
      ~map_done:(fun _ ->
		   close_fdlist();
		   try
		     Shell.postprocess_job ?ignore_error_code ji;
		     `Done (job_status ji)
		   with
		       Shell.Subprocess_error _ as error ->
			 `Error error
		)
      ~map_error:(fun error ->
		    close_fdlist();
		    Shell_sys.cancel_job ji;
		    `Error error)
      ~map_aborted:(fun () ->
		      close_fdlist();
		      Shell_sys.cancel_job ji;
		      `Aborted)
      (eng :> unit engine)

  method job = job
  method job_instance = ji
end
;;