In Ocaml, how to get stdout string from subprocess? -
In Ocaml, how to get stdout string from subprocess? -
i'm working ocaml , need start new process , communicate it.
if subprocess terminated 1 time it's called , produced output, how retrieve strings in it's stdout?
what if subprocess never terminates? is, everytime given string stdin, produce result stdout, how fetch result?
use unix.open_process_in function. spawn process , homecoming input channel, allow read info process.
if want wait process terminate, can read info (i.e., wait until process pipe returns eof), , close channel, e.g.,
(* [run cmd] runs shell command, waits until terminates, , returns list of strings process outputed *) allow run cmd = allow inp = unix.open_process_in cmd in allow r = in_channel.input_lines inp in in_channel.close inp; r working non-terminating process easier.
you may find interesting lwt library has descent interface multiprocessing. , async library asynchronous library provide first-class interface multiprocessing. although, libraries great, little bit advance, simple cases standard unix module enough.
subprocess ocaml stdout
Comments
Post a Comment