-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.ml
70 lines (58 loc) · 1.72 KB
/
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#load "unix.cma"
exception Cancel
let ls_dir dir exts =
Sys.readdir dir
|> Array.to_list
|> List.filter (fun f -> List.mem (Filename.extension f) exts)
|> List.sort compare
let lines_of_file path =
let rec lines_of_file' channel lines = match input_line channel with
| exception End_of_file -> List.rev lines
| l -> lines_of_file' channel (l :: lines) in
try
let channel = open_in path in
let lines = lines_of_file' channel [] in
close_in channel ;
lines
with
| Sys_error _ -> []
(* TODO : lire multiline (récursion) *)
let output_of_command command =
let cin = Unix.open_process_in command in
try
let output = input_line cin in
let _ = Unix.close_process_in cin in
output
with
| End_of_file -> raise Cancel
let program_is_running program =
let ps = output_of_command ("ps -ef | grep -v grep | grep -cw "
^ program) in
String.length ps > 0
let input_of_command writer command =
let cout = Unix.open_process_out command in
writer cout ;
(match Unix.close_process_out cout with
| Unix.WEXITED code when code = 0 -> ()
| _ -> raise Cancel)
let checklist_template height title subtitle choices =
"zenity "
^ "--window-icon=question "
^ "--list "
^ "--checklist "
^ "--height=" ^ string_of_int height ^ " "
^ "--title=\"" ^ title ^ "\" "
^ "--column=\"\" "
^ "--column=\"" ^ subtitle ^ "\" "
^ choices
let progressbar_template title =
"zenity "
^ "--progress "
^ "--title=\"" ^ title ^ "\" "
^ "--text=\"\" "
^ "--percentage=0 "
^ "--auto-close"
let info_template text =
"zenity --info --text=" ^ text
let error_template text =
"zenity --error --text=" ^ text