-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathrun_command.ml
52 lines (46 loc) · 1.95 KB
/
run_command.ml
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
44
45
46
47
48
49
50
51
52
(**************************************************************************)
(* *)
(* OCaml *)
(* *)
(* Sebastien Hinderer, projet Gallium, INRIA Paris *)
(* *)
(* Copyright 2016 Institut National de Recherche en Informatique et *)
(* en Automatique. *)
(* *)
(* All rights reserved. This file is distributed under the terms of *)
(* the GNU Lesser General Public License version 2.1, with the *)
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)
(* Run programs and log their stdout/stderr, with a timer... *)
open Ocamltest_stdlib
type settings = {
progname : string;
argv : string array;
envp : string array;
stdin_filename : string;
stdout_filename : string;
stderr_filename : string;
append : bool;
timeout : int;
log : out_channel;
}
let settings_of_commandline ?(stdout_fname="") ?(stderr_fname="") commandline =
let words = String.words commandline in
let quoted_words =
if Sys.win32
then List.map Filename.maybe_quote words
else words in
{
progname = List.hd quoted_words;
argv = Array.of_list quoted_words;
envp = [||];
stdin_filename = "";
stdout_filename = stdout_fname;
stderr_filename = stderr_fname;
append = false;
timeout = 0;
log = stderr
}
external run : settings -> int = "caml_run_command"
let run_commandline commandline = run (settings_of_commandline commandline)