Convert Process.create_process_and_wait to Core.Std.Unix

Reviewed By: jeremydubreil

Differential Revision: D4232432

fbshipit-source-id: 52fb7eb
master
Josh Berdine 8 years ago committed by Facebook Github Bot
parent 81d616a50b
commit c094287428

@ -29,15 +29,15 @@ let print_error_and_exit ?(exit_code=1) fmt =
terminate. The standard out and error are not redirected. If the command fails to execute, terminate. The standard out and error are not redirected. If the command fails to execute,
print an error message and exit. *) print an error message and exit. *)
let create_process_and_wait ~prog ~args = let create_process_and_wait ~prog ~args =
let pid = let open! Core.Std in
Unix.create_process prog (Array.of_list (prog :: args)) Unix.stdin Unix.stdout Unix.stderr in Unix.fork_exec ~prog ~args:(prog :: args) ()
let _, status = Unix.waitpid [] pid in |> Unix.waitpid
let exit_code = match status with |> function
| Unix.WEXITED i -> i | Ok () -> ()
| _ -> 1 in | Error err as status ->
if exit_code <> 0 then L.do_err "Executing: %s@\n%s@\n"
print_error_and_exit ~exit_code:exit_code (String.concat ~sep:" " (prog :: args)) (Unix.Exit_or_signal.to_string_hum status) ;
"Failed to execute: %s\n" (String.concat ~sep:" " (prog :: args)) exit (match err with `Exit_non_zero i -> i | `Signal _ -> 1)
(** Given a process id and a function that describes the command that the process id (** Given a process id and a function that describes the command that the process id
represents, prints a message explaining the command and its status, if in debug or stats mode. represents, prints a message explaining the command and its status, if in debug or stats mode.

Loading…
Cancel
Save