Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call a program written in python in a program written in Ocaml

Tags:

python

ocaml

I wanted to ask if you could call in a program written in Ocaml a program written in python , and if the answer is yes how do I do?

like image 710
kafka Avatar asked Nov 27 '25 20:11

kafka


1 Answers

What exactly are you intending to do? Do you want to run it and forget about it? Then do a fork/exec. Do you want run it and wait until it's finished but otherwise do nothing? Then use Sys.command. Do you want to read/write to it? Then uses Unix.open_process* (or Unix.create_process*).

For example, if I want to run ls and print out the results, I can do this:

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
like image 87
Niki Yoshiuchi Avatar answered Nov 30 '25 11:11

Niki Yoshiuchi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!