let output_of_file_name file_name variables =
try
let source_command_line =
(* This is very important: dash does not support "source", you have to use the
less readable, but more portable, ".": *)
Printf.sprintf "set -e; (. %s 2> /dev/null &&" file_name in
let command_line =
List.fold_left
(fun string variable ->
(* Print a line with: the variable name, a space, and its value *)
Printf.sprintf "%s echo %s $%s && " string variable variable)
source_command_line
variables in
let command_line = command_line ^ " true) 2> /dev/null" in
(* Printf.printf "The command line is %s\n" command_line; *)
let (output, exit_code) = Unix.run command_line in
if not (exit_code = Unix.WEXITED 0) then
failwith ("Failed when source'ing the configuration file " ^ file_name)
else begin
(* Printf.printf "The output is:\n-------------------------\n%s\n-------------------------\n" output; *)
output;
end
with _ -> begin
(* Printf.printf "WARNING: could not source %s\n" file_name; *)
"";
end