author | traytel |
Tue, 03 Mar 2015 19:08:04 +0100 | |
changeset 59580 | cbc38731d42f |
parent 47499 | 4b0daca2bf88 |
permissions | -rw-r--r-- |
40748
591b6778d076
removed bash from ML system bootstrap, and past the Secure ML barrier;
wenzelm
parents:
39583
diff
changeset
|
1 |
(* Title: Pure/Concurrent/bash_sequential.ML |
26220 | 2 |
Author: Makarius |
3 |
||
35010
d6e492cea6e4
renamed system/system_out to bash/bash_output -- to emphasized that this is really GNU bash, not some undefined POSIX sh;
wenzelm
parents:
29564
diff
changeset
|
4 |
Generic GNU bash processes (no provisions to propagate interrupts, but |
d6e492cea6e4
renamed system/system_out to bash/bash_output -- to emphasized that this is really GNU bash, not some undefined POSIX sh;
wenzelm
parents:
29564
diff
changeset
|
5 |
could work via the controlling tty). |
26220 | 6 |
*) |
7 |
||
44054 | 8 |
signature BASH = |
9 |
sig |
|
47499
4b0daca2bf88
redirect bash stderr to Isabelle warning as appropriate -- avoid raw process error output which may either get ignored or overload PIDE syslog in extreme cases;
wenzelm
parents:
44054
diff
changeset
|
10 |
val process: string -> {out: string, err: string, rc: int, terminate: unit -> unit} |
44054 | 11 |
end; |
12 |
||
13 |
structure Bash: BASH = |
|
43850
7f2cbc713344
moved bash operations to Isabelle_System (cf. Scala version);
wenzelm
parents:
43847
diff
changeset
|
14 |
struct |
7f2cbc713344
moved bash operations to Isabelle_System (cf. Scala version);
wenzelm
parents:
43847
diff
changeset
|
15 |
|
7f2cbc713344
moved bash operations to Isabelle_System (cf. Scala version);
wenzelm
parents:
43847
diff
changeset
|
16 |
fun process script = |
26220 | 17 |
let |
40749 | 18 |
val id = serial_string (); |
19 |
val script_path = File.tmp_path (Path.basic ("bash_script" ^ id)); |
|
47499
4b0daca2bf88
redirect bash stderr to Isabelle warning as appropriate -- avoid raw process error output which may either get ignored or overload PIDE syslog in extreme cases;
wenzelm
parents:
44054
diff
changeset
|
20 |
val out_path = File.tmp_path (Path.basic ("bash_out" ^ id)); |
4b0daca2bf88
redirect bash stderr to Isabelle warning as appropriate -- avoid raw process error output which may either get ignored or overload PIDE syslog in extreme cases;
wenzelm
parents:
44054
diff
changeset
|
21 |
val err_path = File.tmp_path (Path.basic ("bash_err" ^ id)); |
4b0daca2bf88
redirect bash stderr to Isabelle warning as appropriate -- avoid raw process error output which may either get ignored or overload PIDE syslog in extreme cases;
wenzelm
parents:
44054
diff
changeset
|
22 |
fun cleanup () = (try File.rm script_path; try File.rm out_path; try File.rm err_path); |
40749 | 23 |
in |
24 |
let |
|
25 |
val _ = File.write script_path script; |
|
26 |
val status = |
|
27 |
OS.Process.system |
|
28 |
("exec \"$ISABELLE_HOME/lib/scripts/process\" no_group /dev/null" ^ |
|
47499
4b0daca2bf88
redirect bash stderr to Isabelle warning as appropriate -- avoid raw process error output which may either get ignored or overload PIDE syslog in extreme cases;
wenzelm
parents:
44054
diff
changeset
|
29 |
" script \"exec bash " ^ File.shell_path script_path ^ |
4b0daca2bf88
redirect bash stderr to Isabelle warning as appropriate -- avoid raw process error output which may either get ignored or overload PIDE syslog in extreme cases;
wenzelm
parents:
44054
diff
changeset
|
30 |
" > " ^ File.shell_path out_path ^ |
4b0daca2bf88
redirect bash stderr to Isabelle warning as appropriate -- avoid raw process error output which may either get ignored or overload PIDE syslog in extreme cases;
wenzelm
parents:
44054
diff
changeset
|
31 |
" 2> " ^ File.shell_path err_path ^ "\""); |
40749 | 32 |
val rc = |
33 |
(case Posix.Process.fromStatus status of |
|
34 |
Posix.Process.W_EXITED => 0 |
|
35 |
| Posix.Process.W_EXITSTATUS w => Word8.toInt w |
|
36 |
| Posix.Process.W_SIGNALED s => 256 + LargeWord.toInt (Posix.Signal.toWord s) |
|
37 |
| Posix.Process.W_STOPPED s => 512 + LargeWord.toInt (Posix.Signal.toWord s)); |
|
26220 | 38 |
|
47499
4b0daca2bf88
redirect bash stderr to Isabelle warning as appropriate -- avoid raw process error output which may either get ignored or overload PIDE syslog in extreme cases;
wenzelm
parents:
44054
diff
changeset
|
39 |
val out = the_default "" (try File.read out_path); |
4b0daca2bf88
redirect bash stderr to Isabelle warning as appropriate -- avoid raw process error output which may either get ignored or overload PIDE syslog in extreme cases;
wenzelm
parents:
44054
diff
changeset
|
40 |
val err = the_default "" (try File.read err_path); |
40749 | 41 |
val _ = cleanup (); |
47499
4b0daca2bf88
redirect bash stderr to Isabelle warning as appropriate -- avoid raw process error output which may either get ignored or overload PIDE syslog in extreme cases;
wenzelm
parents:
44054
diff
changeset
|
42 |
in {out = out, err = err, rc = rc, terminate = fn () => ()} end |
40749 | 43 |
handle exn => (cleanup (); reraise exn) |
44 |
end; |
|
26220 | 45 |
|
43850
7f2cbc713344
moved bash operations to Isabelle_System (cf. Scala version);
wenzelm
parents:
43847
diff
changeset
|
46 |
end; |
7f2cbc713344
moved bash operations to Isabelle_System (cf. Scala version);
wenzelm
parents:
43847
diff
changeset
|
47 |