如果您只想运行程序而不与它通信,请使用Sys.command.
let exit_code = Sys.command "c:\\path\\to\\executable.exe /argument" in
(* if exit_code=0, the command succeeded. Otherwise it failed. *)
Run Code Online (Sandbox Code Playgroud)
对于更复杂的情况,您需要使用模块中的函数Unix.尽管有这个名字,但大多数都在Windows下工作.例如,如果需要从命令获取输出:
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 …
Run Code Online (Sandbox Code Playgroud)