我想问一下你能不能在一个用Ocaml写的程序中调用一个用python写的程序,如果可以怎么办?
最佳答案
您到底打算做什么?你想运行它而忘记它吗?然后做一个fork/exec。您想运行它并等到它完成,否则什么都不做吗?然后使用 Sys.command
。你想读/写它吗?然后使用 Unix.open_process*
(或 Unix.create_process*
)。
例如,如果我想运行 ls
并打印出结果,我可以这样做:
let ls = Unix.open_process_in "ls"
try
while true do
Printf.printf "%s\n" (input_line ls)
done
with End_of_file -> ()
Unix.close_process_in ls
关于python - 在Ocaml写的程序中调用python写的程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4683639/