快速提问。如何在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/