From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 6CFE17F0AB for ; Thu, 23 Mar 2017 15:24:54 +0100 (CET) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=zhenya1007@gmail.com; spf=Pass smtp.mailfrom=zhenya1007@gmail.com; spf=None smtp.helo=postmaster@mail-yw0-f173.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of zhenya1007@gmail.com) identity=pra; client-ip=209.85.161.173; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="zhenya1007@gmail.com"; x-sender="zhenya1007@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of zhenya1007@gmail.com designates 209.85.161.173 as permitted sender) identity=mailfrom; client-ip=209.85.161.173; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="zhenya1007@gmail.com"; x-sender="zhenya1007@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-yw0-f173.google.com) identity=helo; client-ip=209.85.161.173; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="zhenya1007@gmail.com"; x-sender="postmaster@mail-yw0-f173.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AhNaqBhbtk736dFCkhQ5e6in/LSx+4OfEezUN459i?= =?us-ascii?q?sYplN5qZr8+7bnLW6fgltlLVR4KTs6sC0LuK9fi4EUU7or+5+EgYd5JNUxJXwe?= =?us-ascii?q?43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6arXK99yMdFQviPgRp?= =?us-ascii?q?OOv1BpTSj8Oq3Oyu5pHfeQtFiT6ybL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qq?= =?us-ascii?q?g94Do7FI+nC8+XVICghq2IhX/jQbVZY2lHDhaHFnK+JNbMYOsFdC/HepwpqTcD?= =?us-ascii?q?T7X0E4I=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0CrKgBy2dNYgK2hVdFdHAEBBAEBCgEBG?= =?us-ascii?q?AEFAQsBgkOBBT+BCweDW5o1BoEjiB5mhCeIHoIOKoV4AoMOB0EWAQEBAQEBAQE?= =?us-ascii?q?BAQESAQEJDQkIJjGCMyCCQwECAgEjBBkBGxEMAQMBCwYDAgs3AgIiAREBBQEcG?= =?us-ascii?q?RuJUgEDCAUIDo0MkRk/jAOBbBgFARyDCQWDYQoZJw1VgiUBAQEBBgEBAQEBAQE?= =?us-ascii?q?ZAgYShXeFNIUBglmCXwWBKwEBAYd3kxcPCAEBgTwJhTaLT4F7VIELhyKGM5IaF?= =?us-ascii?q?B+BFSYGgS9ZVhdQgTiCKoIrJDUBiggBAQE?= X-IPAS-Result: =?us-ascii?q?A0CrKgBy2dNYgK2hVdFdHAEBBAEBCgEBGAEFAQsBgkOBBT+?= =?us-ascii?q?BCweDW5o1BoEjiB5mhCeIHoIOKoV4AoMOB0EWAQEBAQEBAQEBAQESAQEJDQkIJ?= =?us-ascii?q?jGCMyCCQwECAgEjBBkBGxEMAQMBCwYDAgs3AgIiAREBBQEcGRuJUgEDCAUIDo0?= =?us-ascii?q?MkRk/jAOBbBgFARyDCQWDYQoZJw1VgiUBAQEBBgEBAQEBAQEZAgYShXeFNIUBg?= =?us-ascii?q?lmCXwWBKwEBAYd3kxcPCAEBgTwJhTaLT4F7VIELhyKGM5IaFB+BFSYGgS9ZVhd?= =?us-ascii?q?QgTiCKoIrJDUBiggBAQE?= X-IronPort-AV: E=Sophos;i="5.36,210,1486422000"; d="scan'208,217";a="217783028" Received: from mail-yw0-f173.google.com ([209.85.161.173]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 23 Mar 2017 15:24:52 +0100 Received: by mail-yw0-f173.google.com with SMTP id d191so20885748ywe.2 for ; Thu, 23 Mar 2017 07:24:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=EPf6kQ3LP8UI2BPp3RciUG+ksgjZXICSyGOyeKhPmxE=; b=TOJtc+W5VVgvX53Cf6EIqjwT+LKDjiZfyh8vkt1IutsqevTjtH4IzmVRmVay0KORSN E6AIM/Efu5uceqM/Y5/+f/OPw5ICzrcRm78u42fdL6nOZ99ENUZhUo0YxoAbGtZAcpVr pZ65IF3s9dIFo4IsNM0oZFIdOn8LiCgEgOeYw1TIpblYFrshfADjV151H2vy3FIHlURe Z9Rg8Ze0Wg2Zr+jbnCVEf7YM4z0n+D9CslNnw9KpwNQVjZbY0IOdmZndeUhs+TLpR7Bo I22YqwJJfZmmexXU3PyPpSxfasw479hoz59OBayzUXmQ5s4Y2BjW6DMALHUnSpoClKuG BoyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=EPf6kQ3LP8UI2BPp3RciUG+ksgjZXICSyGOyeKhPmxE=; b=FeHjESGa3Vq9NjM75RHUEyBJ3OXrCPLuSR3/BAW0uoefnYHNAMYAh267HJfdSSQcY/ DXK6TSTDjwZhEkXmtMSqCuk/nWfvTJpUdO/4IhrZSDjAWsaRMMLwyDYwBZicqV4XQ/Fj nb1+B5fFlEjnrS6E9u5VeCNQDxl8vSibJRWq1qFMcHmAUdfBWkp27o1xnZi7UFcFWH6X P2lW05pzCiGhgkYplpBbgyDClI/60TF8GXhLi3xYXoh9bVQIpenJoxyHqJOy5Cp3EQRe HEIvpt925ZtKvPF2zV4CaEON3GSQpzciL9ZHRiaEMFrgS+pUltBuyiHXBFBRL0p/hNd0 2Wng== X-Gm-Message-State: AFeK/H0ngNfkabw+E92/h0cAoR4mHtX2s0hQxYPRhFDowJoISsiAeEXbipSu7YSYuEw4alFr9n7rq1h1pBsufg== X-Received: by 10.129.102.136 with SMTP id a130mr1954110ywc.144.1490279091347; Thu, 23 Mar 2017 07:24:51 -0700 (PDT) MIME-Version: 1.0 Received: by 10.37.164.99 with HTTP; Thu, 23 Mar 2017 07:24:50 -0700 (PDT) In-Reply-To: <1590236478.9253508.1490261850094.JavaMail.zimbra@edu.univ-fcomte.fr> References: <1590236478.9253508.1490261850094.JavaMail.zimbra@edu.univ-fcomte.fr> From: Evgeny Roubinchtein Date: Thu, 23 Mar 2017 10:24:50 -0400 Message-ID: To: paul.lachat@edu.univ-fcomte.fr Cc: caml-list@inria.fr Content-Type: multipart/alternative; boundary=001a1149097adb4b52054b66a30a Subject: Re: [Caml-list] [Question] Loading .ml in memory to interact with them. --001a1149097adb4b52054b66a30a Content-Type: text/plain; charset=UTF-8 Just to be clear: does this need to work on Windows, or only on Unix-like systems? If it only needs to work under Unix, then your problem sounds to me like a standard inter-process communication problem with the usual solutions being to use a combination of pipe(), dup2(), and select() system calls, and with the alternative solution being to use a pseudo-terminal. Chapter 5 of "Unix System Programming in OCaml" https://ocaml.github.io/ocamlunix/pipes.html should give you some guidance on implementing the former solution. If you want to use pseudo-terminals, I don't know of a freely-available tutorial-style reference off the top of my head. "Advanced Programming in the Unix Environment" by late Richard Stevens has had a chapter dedicated to pseudo-terminals since the first edition of the book: perhaps your local library has a copy. Failing that, you could read Linux man page for pty(7), and follow the links to forkpty and friends. For example, you could start here: http://man7.org/linux/man-pages/man7/pty.7.html. The fact that you want to do all of this from Matlab is an extra challenge, but I don't think it's an insurmountable challenge. Even if Matlab doesn't have the functions you need "out of the box", it is possible to extend Matlab with C code, so you could implement a C function to initialize the external process, and another function to send to the external process and receive results. The following is probably a good starting point for learning how to extend Matlab with C/C++: https://www.mathworks.com/help/matlab/call-mex-files-1.html. I don't know off the top of my head if Matlab already comes with sufficiently flexible functionality for communicating with an external process: you could try searching the documentation and/or engaging Mathworks technical support (assuming your license comes with technical support) and/or asking on Mathworks forums. -- Best of luck Zhenya On Thu, Mar 23, 2017 at 5:37 AM, wrote: > Hello, > > I need to find a way to put Ocaml program in memory so I could interact > with the program > (call function, get result, find information about the variables, ...) > without always reading the file. > > That what append when we use the directive #use "file.ml";; in the > interactive shell (the toplevel, when you type the command ocaml in a > shell). > > The instruction need to come from a Matlab function. So, I was thinking to > create a process who run the ocaml command, > redirect his standard input in a named pipe, redirect his standard output > in another named pipe, so I could send instructions and received responses. > > But when I send the first instruction (ex : #use "file.ml";;\n), the > ocaml process send back the response and stop. > > ____ > > file.ml : > let x = 10;; > > ____ > > "#use "file.ml";;\n" > Matlab -- /tmp/pipe_in --> ocaml > > "val x : int = 10" > Matlab <-- /tmp/pipe_out -- ocaml > then ocaml stop... > > ___ > > > So I would like to know if you think it's a good solution and if it is, do > someone know how could I make it work ? > > _ > > I've tried another solution. I use Unix.fork() and launch, in the son > process, the ocaml command then > I send instructions from the father process to the son process with anonym > pipe (Unix.pipe()). > > But here I have trouble with blocking read, I send an instruction, read > the answer but even if I've read all char of the answer, it's wait to read > more but there is no more to read... > > I have tried to use Unix.set_nonblock() and catch EAGAIN, but then I don't > get anything at all in the buffer given to Unix.read(). > > If someone could help, I would be grateful ! > Lachat Paul > > --001a1149097adb4b52054b66a30a Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Just to be clear: does this need to work on Windows, or on= ly on Unix-like systems?=C2=A0 If it only needs to work under Unix, then yo= ur problem sounds to me like a standard inter-process communication problem= with the usual solutions being to use a combination of pipe(), dup2(), and= select() system calls, and with the alternative solution being to use a ps= eudo-terminal.=C2=A0 Chapter 5 of "Unix System Programming in OCaml&qu= ot;=C2=A0https://o= caml.github.io/ocamlunix/pipes.html should give you some guidance on im= plementing the former solution.=C2=A0 If you want to use pseudo-terminals, = I don't know of a freely-available tutorial-style reference off the top= of my head. =C2=A0"Advanced Programming in the Unix Environment"= by late Richard Stevens has had a chapter dedicated to pseudo-terminals si= nce the first edition of the book: perhaps your local library has a copy.= =C2=A0 Failing that, you could read Linux man page for pty(7), and follow t= he links to forkpty and friends.=C2=A0 For example, you could start here:= =C2=A0http://ma= n7.org/linux/man-pages/man7/pty.7.html.

The fact tha= t you want to do all of this from Matlab is an extra challenge, but I don&#= 39;t think it's an insurmountable challenge.=C2=A0 Even if Matlab doesn= 't have the functions you need "out of the box", it is possib= le to extend Matlab with C code, so you could implement a C function to ini= tialize the external process, and another function to send to the external = process and receive results.=C2=A0 The following is probably a good startin= g point for learning how to extend Matlab with C/C++:=C2=A0https://www.mathwor= ks.com/help/matlab/call-mex-files-1.html.=C2=A0 I don't know off th= e top of my head if Matlab already comes with sufficiently flexible functio= nality for communicating with an external process: you could try searching = the documentation and/or engaging Mathworks technical support (assuming you= r license comes with technical support) and/or asking on Mathworks forums.<= /div>

--=C2=A0
Best of luck
Zhenya

On Thu,= Mar 23, 2017 at 5:37 AM, <paul.lachat@edu.univ-fcomte.fr> wrote:
Hel= lo,

I need to find a way to put Ocaml program = in memory so I could interact with the program
(call function, ge= t result, find information about the variables, ...) without always reading= the file.

That what append when we use the di= rective #use "file.ml= ";; in the interactive shell (the toplevel, when you type the command = ocaml in a shell).

The instruction need to com= e from a Matlab function. So, I was thinking to create a process who run th= e ocaml command,
redirect his standard input in a named pipe, red= irect his standard output in another named pipe, so I could send instructio= ns and received responses.

But when I send the= first instruction (ex : #use "file.ml";;\n), the ocaml process send back the response and = stop.

____

let x = =3D 10;;

____

=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "#use "file.ml";;\n"
Matlab --=C2=A0= =C2=A0 /tmp/pipe_in=C2=A0 -->=C2=A0=C2=A0 ocaml

=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "val x : int =3D 10"
<= /div>
Matlab <-- /tmp/pipe_out --=C2=A0=C2=A0=C2=A0 ocaml
<= div>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 then ocaml stop...

___

So I would like to know if you think it's a= good solution and if it is, do someone know how could I make it work ?
=

_

I've tried ano= ther solution. I use Unix.fork() and launch, in the son process, the ocaml = command then
I send instructions from the father process to the s= on process with anonym pipe (Unix.pipe()).

But= here I have trouble with blocking read, I send an instruction, read the an= swer but even if I've read all char of the answer, it's wait to rea= d
more but there is no more to read...

I= have tried to use Unix.set_nonblock() and catch EAGAIN, but then I don'= ;t get anything at all in the buffer given to Unix.read().
If someone could help, I would be grateful !
Lac= hat Paul


--001a1149097adb4b52054b66a30a--