Skip to content

Instantly share code, notes, and snippets.

@ajdawson
Created October 24, 2016 19:57
Show Gist options
  • Save ajdawson/930ce9ce3a163057e19c96f3639016b8 to your computer and use it in GitHub Desktop.
Save ajdawson/930ce9ce3a163057e19c96f3639016b8 to your computer and use it in GitHub Desktop.
Communicating with an ssh process in OCaml
let output_command channel cmd = output_string channel (cmd ^ "\n")
let do_ssh_hostname () =
let oc_in, oc_out = Unix.open_process "ssh -T hostname" in
output_command oc_out "hostname";
flush oc_out;
try
Printf.printf "%s\n" (input_line oc_in)
with
End_of_file -> ();
ignore (Unix.close_process (oc_in, oc_out)) ;;
let () = do_ssh_hostname ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment