From: Pawel Wojciechowski <Pawel.Wojciechowski@cl.cam.ac.uk>
To: caml-list@inria.fr
Cc: Pawel.Wojciechowski@cl.cam.ac.uk
Subject: Conversion between file descriptors and strings
Date: Mon, 10 Mar 1997 14:01:57 +0000 [thread overview]
Message-ID: <E0w45eJ-0002gB-00@heaton.cl.cam.ac.uk> (raw)
Hi all,
I just started programming in the Objective Caml language. At the current
stage of my project, I need to implement a communication between a process
and its child process, which is created by 'fork'. I decided to use pipes
from the Unix library. Instead of exchanging standard descriptors (0 and 1)
for descriptors fd_in and fd_out created by 'pipe' (as in the expression
(fd_out, fd_in) = pipe()), I'd prefer to pass descriptors fd_out and fd_in,
to a program executed as a forked process, as arguments when invoking
'execvp'. Then, you can pass these values to the program (which is stored
in a separate file and compiled separately) as an array of *strings*
being a structural argument to the 'execvp'.
My question is how to convert a descriptor of type file_descr into a string
and vice-versa?
In C, there is no such problems, since descriptors are integers, and you
can always write accordingly:
sprintf(arg1, "%d", pipe[0])
and
descr = atoi(argv[1])
In strongly-typed (O)Caml, we should expect the following error message:
"This expression has type int but is here used with type Unix.file_descr"
I don't have much experience in using (O)Caml so appologize if you
consider that my problem is trivial but please help me sort it out! :)
regards,
Pawel
ps. Pipe is a function from the Unix library and it has types as follows:
pipe : init -> file_descr * file_desc
reply other threads:[~1997-03-10 14:32 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=E0w45eJ-0002gB-00@heaton.cl.cam.ac.uk \
--to=pawel.wojciechowski@cl.cam.ac.uk \
--cc=caml-list@inria.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