From c094287428331a92492a6f86c9b4725a2463a77d Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Fri, 9 Dec 2016 16:27:28 -0800 Subject: [PATCH] Convert Process.create_process_and_wait to Core.Std.Unix Reviewed By: jeremydubreil Differential Revision: D4232432 fbshipit-source-id: 52fb7eb --- infer/src/base/Process.ml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/infer/src/base/Process.ml b/infer/src/base/Process.ml index afabbf69f..f551cfcbd 100644 --- a/infer/src/base/Process.ml +++ b/infer/src/base/Process.ml @@ -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, print an error message and exit. *) let create_process_and_wait ~prog ~args = - let pid = - Unix.create_process prog (Array.of_list (prog :: args)) Unix.stdin Unix.stdout Unix.stderr in - let _, status = Unix.waitpid [] pid in - let exit_code = match status with - | Unix.WEXITED i -> i - | _ -> 1 in - if exit_code <> 0 then - print_error_and_exit ~exit_code:exit_code - "Failed to execute: %s\n" (String.concat ~sep:" " (prog :: args)) + let open! Core.Std in + Unix.fork_exec ~prog ~args:(prog :: args) () + |> Unix.waitpid + |> function + | Ok () -> () + | Error err as status -> + L.do_err "Executing: %s@\n%s@\n" + (String.concat ~sep:" " (prog :: args)) (Unix.Exit_or_signal.to_string_hum status) ; + 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 represents, prints a message explaining the command and its status, if in debug or stats mode.