author | Christian Urban <urbanc@in.tum.de> |
Wed, 23 Feb 2011 23:55:37 +0000 | |
changeset 458 | 242e81f4d461 |
parent 418 | 1d1e4cda8c54 |
child 472 | 1bbe4268664d |
permissions | -rw-r--r-- |
61 | 1 |
theory ExternalSolver |
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
211
diff
changeset
|
2 |
imports "../Appendix" |
61 | 3 |
begin |
4 |
||
94 | 5 |
|
211
d5accbc67e1b
more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
6 |
section {* Executing an External Application (TBD) \label{rec:external}*} |
61 | 7 |
|
8 |
text {* |
|
9 |
{\bf Problem:} |
|
94 | 10 |
You want to use an external application. |
11 |
\smallskip |
|
12 |
||
418 | 13 |
{\bf Solution:} The function @{ML bash_output} might be the right thing for |
94 | 14 |
you. |
61 | 15 |
\smallskip |
16 |
||
94 | 17 |
This function executes an external command as if printed in a shell. It |
18 |
returns the output of the program and its return value. |
|
19 |
||
20 |
For example, consider running an ordinary shell commands: |
|
21 |
||
22 |
@{ML_response [display,gray] |
|
418 | 23 |
"bash_output \"echo Hello world!\"" "(\"Hello world!\\n\", 0)"} |
94 | 24 |
|
25 |
Note that it works also fine with timeouts (see Recipe~\ref{rec:timeout} |
|
26 |
on Page~\pageref{rec:timeout}), i.e. external applications are killed |
|
27 |
properly. For example, the following expression takes only approximately |
|
28 |
one second: |
|
29 |
||
349
9e374cd891e1
updated to Isabelle changes
Christian Urban <urbanc@in.tum.de>
parents:
346
diff
changeset
|
30 |
@{ML_response_fake [display,gray] |
418 | 31 |
"TimeLimit.timeLimit (Time.fromSeconds 1) bash_output \"sleep 30\" |
94 | 32 |
handle TimeLimit.TimeOut => (\"timeout\", ~1)" "(\"timeout\", ~1)"} |
33 |
||
418 | 34 |
The function @{ML bash_output} can also be used for more reasonable |
94 | 35 |
applications, e.g. coupling external solvers with Isabelle. In that case, |
36 |
one has to make sure that Isabelle can find the particular executable. |
|
37 |
One way to ensure this is by adding a Bash-like variable binding into |
|
38 |
one of Isabelle's settings file (prefer the user settings file usually to |
|
39 |
be found at @{text "$HOME/.isabelle/etc/settings"}). |
|
40 |
||
41 |
For example, assume you want to use the application @{text foo} which |
|
42 |
is here supposed to be located at @{text "/usr/local/bin/"}. |
|
43 |
The following line has to be added to one of Isabelle's settings file: |
|
44 |
||
45 |
@{text "FOO=/usr/local/bin/foo"} |
|
46 |
||
47 |
In Isabelle, this application may now be executed by |
|
48 |
||
418 | 49 |
@{ML_response_fake [display,gray] "bash_output \"$FOO\"" "\<dots>"} |
94 | 50 |
*} |
51 |
||
52 |
||
61 | 53 |
end |