let output_of_environment variables =
let command_line =
List.fold_left
(fun string variable ->
(* Print a line with: the variable name, a space, and its value,
IF the variable is defined in the environment; otherwise don't
print anything, and let the configuration file binding (if any)
take precedence: *)
Printf.sprintf
"%s if test -n \"$%s\"; then echo %s \"$%s\"; fi; "
string variable variable variable)
""
variables in
(* Printf.printf "The command line is\n%s\n" command_line; *)
let (output, exit_code) = Unix.run command_line in
assert(exit_code = Unix.WEXITED 0);
(* Printf.printf "The output is:\n-------------------------\n%s\n-------------------------\n" output; *)
output