Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

running executable (windows) file inside ocaml

Tags:

exe

ocaml

Quick question. How to run an executable file in ocaml? I believe this is possible, but I don't know how.

Please provide an example code.

like image 665
zfm Avatar asked Sep 13 '26 18:09

zfm


1 Answers

If you just want to run a 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 Unix module. Despite the name, most of them work under Windows. For example, if you need to get output from a 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 …
like image 175
Gilles 'SO- stop being evil' Avatar answered Sep 15 '26 18:09

Gilles 'SO- stop being evil'