From: Evgeny Roubinchtein <zhenya1007@gmail.com>
To: paul.lachat@edu.univ-fcomte.fr
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] [Question] Loading .ml in memory to interact with them.
Date: Thu, 23 Mar 2017 10:24:50 -0400 [thread overview]
Message-ID: <CAGYXaSaM=8bEAuGLBNP4TxAEFkRBy7cFNsfsddL3xjmV1jPq-w@mail.gmail.com> (raw)
In-Reply-To: <1590236478.9253508.1490261850094.JavaMail.zimbra@edu.univ-fcomte.fr>
[-- Attachment #1: Type: text/plain, Size: 3788 bytes --]
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, <paul.lachat@edu.univ-fcomte.fr> 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
>
>
[-- Attachment #2: Type: text/html, Size: 5373 bytes --]
next prev parent reply other threads:[~2017-03-23 14:24 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-23 9:37 paul.lachat
2017-03-23 13:02 ` Sébastien Hinderer
2017-03-23 13:26 ` paul.lachat
2017-03-23 13:41 ` Sébastien Hinderer
2017-03-23 13:57 ` paul.lachat
2017-03-23 14:24 ` Evgeny Roubinchtein [this message]
2017-03-23 15:09 ` François Bobot
[not found] ` <CAGYXaSbcqNWcXe1MLm_YyS28N7ji3td=L_jFVv35=50oSxaUDQ@mail.gmail.com>
2017-03-23 15:50 ` François Bobot
2017-03-24 9:04 ` Kim Nguyễn
2017-03-24 14:43 Oleg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAGYXaSaM=8bEAuGLBNP4TxAEFkRBy7cFNsfsddL3xjmV1jPq-w@mail.gmail.com' \
--to=zhenya1007@gmail.com \
--cc=caml-list@inria.fr \
--cc=paul.lachat@edu.univ-fcomte.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox