Quick question. How to run an executable file in ocam开发者_Go百科l? I believe this is possible, but I don't know how.
Please provide an example code.
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 …
精彩评论