开发者

running executable (windows) file inside ocaml

开发者 https://www.devze.com 2023-03-10 10:55 出处:网络
Quick question. How to run an executable file in ocam开发者_Go百科l? I believe this is possible, but I don\'t know how.

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 …
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号