【问题标题】:running executable (windows) file inside ocaml在 ocaml 中运行可执行(Windows)文件
【发布时间】:2011-06-03 17:14:42
【问题描述】:

快速提问。如何在 ocaml 中运行可执行文件?我相信这是可能的,但我不知道如何。

请提供示例代码。

【问题讨论】:

标签: ocaml exe


【解决方案1】:

如果您只想运行一个程序而不与它通信,请使用Sys.command

let exit_code = Sys.command "c:\\path\\to\\executable.exe /argument" in
(* if exit_code=0, the command succeeded. Otherwise it failed. *)

对于更复杂的情况,您需要使用functions in the Unix module。尽管有这个名字,most of them 在 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 …

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-04
    • 2014-09-16
    • 1970-01-01
    • 1970-01-01
    • 2012-02-11
    • 1970-01-01
    相关资源
    最近更新 更多