swigra_test.ml
1.02 KB
let start_server () =
let serv_in, serv_out, serv_err = Unix.open_process_full "./swigra -w"
[|"PATH=" ^ Sys.getenv "PATH"; "LANG=en_GB.UTF-8"|] in
ignore @@ input_line serv_in;
serv_in, serv_out, serv_err
let stop_server (serv_in, serv_out, serv_err) =
output_string serv_out "halt.\n";
ignore @@ Unix.close_process_full (serv_in, serv_out, serv_err)
let curl s =
let curl_in, curl_out, curl_err = Unix.open_process_full ("curl 'http://localhost:3333/swigra' --data-urlencode 'q=" ^ s ^ "'")
[|"PATH=" ^ Sys.getenv "PATH"; "LANG=en_GB.UTF-8"|] in
try
while true do
ignore @@ input_line curl_in
done
with End_of_file -> ignore @@ Unix.close_process_full (curl_in, curl_out, curl_err)
let print_xml () =
let xml_in = open_in "httpd/forest-disamb.xml" in
try
while true do
print_endline @@ input_line xml_in
done
with End_of_file -> close_in xml_in
let _ =
let server = start_server () in
curl "Ala ma kota.";
print_xml ();
curl "Ala ma psa.";
print_xml ();
stop_server server