[Libguestfs] [PATCH 1/2] add run_shell helper

Olaf Hering olaf at aepfle.de
Tue Apr 9 17:27:01 UTC 2013


The new run_shell helper is a copy of run_python,
and will be used by upcoming changes.

Signed-off-by: Olaf Hering <olaf at aepfle.de>
---
 src/supermin_utils.ml  | 9 +++++++++
 src/supermin_utils.mli | 5 +++++
 2 files changed, 14 insertions(+)

diff --git a/src/supermin_utils.ml b/src/supermin_utils.ml
index f98e09a..cb8a27e 100644
--- a/src/supermin_utils.ml
+++ b/src/supermin_utils.ml
@@ -70,6 +70,15 @@ let run_command cmd =
     exit 1
   )
 
+let run_shell code args =
+  let cmd = sprintf "sh -c %s arg0 %s"
+    (Filename.quote code)
+    (String.concat " " (List.map Filename.quote args)) in
+  if Sys.command cmd <> 0 then (
+    eprintf "supermin: external shell program failed, see earlier error messages\n";
+    exit 1
+  )
+
 let run_python code args =
   let cmd = sprintf "python -c %s %s"
     (Filename.quote code)
diff --git a/src/supermin_utils.mli b/src/supermin_utils.mli
index 54df1e8..c4a52c6 100644
--- a/src/supermin_utils.mli
+++ b/src/supermin_utils.mli
@@ -41,6 +41,11 @@ val run_command : string -> unit
       when constructing the command to properly quote any arguments
       (using {!Filename.quote}). *)
 
+val run_shell : string -> string list -> unit
+  (** [run_shell code args] runs shell [code] with arguments [args].
+      This does not return anything, but exits with an error message
+      if the shell code returns an error. *)
+
 val run_python : string -> string list -> unit
   (** [run_python code args] runs Python [code] with arguments [args].
       This does not return anything, but exits with an error message




More information about the Libguestfs mailing list