ocaml - 在ocaml中运行可执行(windows)文件

标签 ocaml exe

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

请提供示例代码。

最佳答案

如果你只是想运行一个程序而不想与之通信,使用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 …

关于ocaml - 在ocaml中运行可执行(windows)文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6230396/

相关文章:

debugging - 在OCaml中进行跟踪和调试

ocaml - OCaml 中的高阶类型(幻像类型子类型化)

java - 如何将 Java 程序转换为 .exe 文件?

windows - 参见 .exe 的 std::cout

java - 为什么我的java代码在eclipse中运行而不是作为.exe运行。或 .class 文件

module - 错误 : Cannot safely evaluate the definition of the recursively-defined module

ocaml - 为什么我的 ocaml 模块未定义?

c# - native 可执行文件中的字符串表资源

php - IE9 中的 "This type of file could harm your computer"消息

bit-manipulation - OCaml 中高效的 8 位和 16 位计算