Conversion between file descriptors and strings

From: Pawel Wojciechowski (
Date: Mon Mar 10 1997 - 15:01:57 MET

Subject: Conversion between file descriptors and strings
Date: Mon, 10 Mar 1997 14:01:57 +0000
From: Pawel Wojciechowski <>
Message-Id: <>

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])


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! :)



ps. Pipe is a function from the Unix library and it has types as follows:

pipe : init -> file_descr * file_desc

This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:09 MET