Browse Source

Display result of command just launched

Leo 10 years ago
parent
commit
a4a504bac4
2 changed files with 13 additions and 2 deletions
  1. 0 1
      src/default.ml
  2. 13 1
      src/exec_cmd.ml

+ 0 - 1
src/default.ml

@@ -54,6 +54,5 @@ let run ~rc:rc_content ~tmp:tmp_content cmd_number =
     | Some num -> begin
         let cmd_to_exec = Exec_cmd.num_cmd_to_cmd ~cmd_list:rc_content.progs num in
           Exec_cmd.execute ~tmp:tmp_content cmd_to_exec;
-          ()
       end
 ;;

+ 13 - 1
src/exec_cmd.ml

@@ -73,10 +73,22 @@ let log ?(func= (+) 1 ) ~file_name =
     | _ -> failwith "Incorrect format"
 ;;
 
+(* Display an error message if command can't run
+ * if 0 status, do nothing
+ * else display status number *)
+let display_result command status =
+    match status with
+    | 0 -> (* No problem, do nothing *) ()
+    | _ -> (* Problem occur,  display it *)
+            printf "Problem while running: '%s'\nExited with code: %i\n"
+            command status
+;;
+
 (* Execute some command and log it *)
 let execute ?(display=true) ~tmp cmd =
     log ~func:((+) 1) ~file_name:tmp;
     if display then
         print_endline cmd;
-    Sys.command cmd;
+    Sys.command cmd
+    |> display_result cmd (* Make it settable in rc file *)
 ;;