Running executable file (windows) inside ocaml

Quick question. How to run an executable in ocaml? I believe that this is possible, but I do not know how to do it.

Provide sample code.

+3
source share
1 answer

If you just want to run the program and not communicate with it, use Sys.command.

let exit_code = Sys.command "c:\\path\\to\\executable.exe /argument" in
(* if exit_code=0, the command succeeded. Otherwise it failed. *)

For more complex cases, you need to use the functions in the moduleUnix . Despite the name, most of them work under Windows. For example, if you need to get the result from the command:

let ch = Unix.open_process_in "c:\\path\\to\\executable.exe /argument" in
try
  while true do
    let line = input_line ch in …
  done
with End_of_file ->
  let status = close_process_in ch in …
+6
source

All Articles