Slave.run: run a command using Unix.execute
authorClinton Ebadi <clinton@unknownlamer.org>
Tue, 6 May 2014 23:19:17 +0000 (19:19 -0400)
committerClinton Ebadi <clinton@unknownlamer.org>
Tue, 6 May 2014 23:19:17 +0000 (19:19 -0400)
Similar to Slave.shell, only it passes the arguments list directly to
Unix.execute.

src/slave.sig
src/slave.sml

index 7471d86..bfe5786 100644 (file)
@@ -46,6 +46,7 @@ signature SLAVE = sig
     val shell : string list -> bool
     val shellF : string list * (string -> string) -> unit
     val shellOutput : string list -> string option
     val shell : string list -> bool
     val shellF : string list * (string -> string) -> unit
     val shellOutput : string list -> string option
+    val run : string * string list -> bool
 
     val concatTo : (string -> bool) -> string -> unit
     (* Search through the result configuration hierarchy for all files matching
 
     val concatTo : (string -> bool) -> string -> unit
     (* Search through the result configuration hierarchy for all files matching
index ba31da8..7e3f9d8 100644 (file)
@@ -82,6 +82,20 @@ fun shellF (ss, msg) =
            ErrorMsg.error NONE (msg s)
     end
 
            ErrorMsg.error NONE (msg s)
     end
 
+fun run (program, argv) =
+    let
+       val proc = Unix.execute (program, argv)
+
+       fun loop inf =
+           case TextIO.inputLine inf of
+               NONE => ()
+             | SOME line => loop inf
+       (* Programs that output will fail unless we eat their output *)
+       val () = loop (Unix.textInstreamOf proc)
+    in
+       OS.Process.isSuccess (Unix.reap proc)
+    end
+
 fun shellOutput ss =
     let
        val proc = Unix.execute ("/bin/bash", ["-c", String.concat ss ^ " 2>&1"])
 fun shellOutput ss =
     let
        val proc = Unix.execute ("/bin/bash", ["-c", String.concat ss ^ " 2>&1"])