开发者

running executable (windows) file inside ocaml

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜