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

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -