module Channel:Generalized channels and file descriptor manipulation.sig
..end
typedescr =
Unix.file_descr
Generalized channels and file descriptor manipulation.
typeany_channel =
[ `InChannel of Pervasives.in_channel | `OutChannel of Pervasives.out_channel ]
typegen_in_channel =
[ `InChannel of Pervasives.in_channel
| `InDescr of descr
| `InFd of int ]
typegen_out_channel =
[ `OutChannel of Pervasives.out_channel
| `OutDescr of descr
| `OutFd of int ]
typegen_channel =
[ `InChannel of Pervasives.in_channel
| `InDescr of descr
| `InFd of int
| `OutChannel of Pervasives.out_channel
| `OutDescr of descr
| `OutFd of int ]
typedup_in_source =
[ `Close
| `Filename of string
| `InChannel of Pervasives.in_channel
| `InDescr of descr
| `InFd of int
| `Null ]
typedup_out_source =
[ `Close
| `Filename of string
| `Filespec of string * clobber_spec
| `Null
| `OutChannel of Pervasives.out_channel
| `OutDescr of descr
| `OutFd of int ]
in_channel
and out_channel
. Returned by Channel.open_thunk
,
Channel.open_command
, and Channel.open_program
.in_channel
and
UNIX file descriptors, both abstract and as int
s.out_channel
and
UNIX file descriptors, both abstract and as int
s.Channel.gen_in_channel
and
Channel.gen_out_channel
.Channel.dup2 (`Filename s, gen)
opens the file s
on
generalized channel gen
.Channel.dup2 (`Close, gen)
closes gen
.Channel.dup2 (`Null, gen)
opens /dev/null
for input
on gen
.`Filespec
allows specifying how an output file is to be
opened according to Channel.clobber_spec
.Channel.dup_in_source
, except that `Filename
uses Channel.clobber
as its open mode.typeclobber_spec =
[ `Append | `AppendOnly | `Clobber | `NoClobber ]
Channel.dup_out_source
.`Clobber
opens the file and truncates it if it exists.`NoClobber
fails if the file exists.`Append
opens the file for appending and creates it if it doesn't
exist.`AppendOnly
opens the file for appending if it exists and fails
otherwise.
Generalized channels and file descriptor manipulation.
typedup_source =
[ `Close
| `Filename of string
| `Filespec of string * clobber_spec
| `InChannel of Pervasives.in_channel
| `InDescr of descr
| `InFd of int
| `Null
| `OutChannel of Pervasives.out_channel
| `OutDescr of descr
| `OutFd of int ]
typedup_spec =
(dup_source * gen_channel) list
typepipe_spec =
gen_channel list
typeprocref =
Proc.t option Pervasives.ref
val clobber : clobber_spec Pervasives.ref
val descr_of_gen : gen_channel -> descr
Channel.descr
underlying a generalized channel. Note that if the
channel is a managed in_channel
or out_channel
, the descriptor
may be closed when the channel is collected.val descr_of_fd : int -> descr
val fd_of_descr : descr -> int
val open_file_in : string -> Pervasives.in_channel
val open_file_out : string -> Pervasives.out_channel
val null_in : unit -> Pervasives.in_channel
/dev/null
for input. Attaches a finalizer.val null_out : unit -> Pervasives.out_channel
/dev/null
for output. Attaches a finalizer.val close_in : Pervasives.in_channel -> unit
val close_out : Pervasives.out_channel -> unit
val close_gen : gen_channel -> unit
val dup2 : dup_source * gen_channel -> unit
Channel.dup2 (src, dest)
copies src
to dest
so that future operations on dest
use src
.
If dest
is an out_channel
, it is flushed first; if dest
in an
in_channel
, its buffer is discarded.
Some sources have special behaviors; see Channel.dup_in_source
and
Channel.dup_out_source
.
val mov2 : dup_source * gen_channel -> unit
Channel.dup2
, but the
source channel is closed after the operation (unless the source and
the destination are the same).val with_dups : dup_spec -> (unit -> 'a) -> 'a
val dup_in : dup_in_source -> Pervasives.in_channel
in_channel
from an input dup source.val dup_out : dup_out_source -> Pervasives.out_channel
out_channel
from an input dup source.val open_thunk : ?pipes:pipe_spec ->
?dups:dup_spec -> (unit -> unit) -> Proc.t * any_channel list
Channel.open_thunk ~pipes ~dups
thunk
forks and calls thunk
in the child process. Any given
dups are performed in the child before calling the thunk. Channels
specified in pipes
are connected to pipes, and the other ends are
returned in a list, along with the Proc.t
of the child process.
The functions Channel.open_thunk_in
, Channel.open_thunk_out
, Channel.open_thunk2
,
and Channel.open_thunk3
are special cases. Rather than return the
Proc.t
, they stash it in the optional argument ?procref
.
val open_thunk_in : ?procref:procref ->
?dups:dup_spec -> (unit -> unit) -> Pervasives.in_channel
stdout
.val open_thunk_out : ?procref:procref ->
?dups:dup_spec -> (unit -> unit) -> Pervasives.out_channel
stdin
.val open_thunk2 : ?procref:procref ->
?dups:dup_spec ->
(unit -> unit) -> Pervasives.in_channel * Pervasives.in_channel
stdout
and stderr
.val open_thunk3 : ?procref:procref ->
?dups:dup_spec ->
(unit -> unit) ->
Pervasives.out_channel * Pervasives.in_channel * Pervasives.in_channel
stdin
, stdout
, and stderr
.val open_command : ?pipes:pipe_spec ->
?dups:dup_spec -> string -> Proc.t * any_channel list
Channel.open_thunk
, but takes a
command to run in the shell.val open_command_in : ?procref:procref ->
?dups:dup_spec -> string -> Pervasives.in_channel
stdout
.val open_command_out : ?procref:procref ->
?dups:dup_spec -> string -> Pervasives.out_channel
stdin
.val open_command2 : ?procref:procref ->
?dups:dup_spec ->
string -> Pervasives.in_channel * Pervasives.in_channel
stdout
and stderr
.val open_command3 : ?procref:procref ->
?dups:dup_spec ->
string ->
Pervasives.out_channel * Pervasives.in_channel * Pervasives.in_channel
stdin
, stdout
, and stderr
.val open_program : ?pipes:pipe_spec ->
?dups:dup_spec ->
?path:bool ->
string -> ?argv0:string -> string list -> Proc.t * any_channel list
Channel.open_thunk
, but takes a program and arguments.val open_program_in : ?procref:procref ->
?dups:dup_spec ->
?path:bool -> string -> ?argv0:string -> string list -> Pervasives.in_channel
stdout
.val open_program_out : ?procref:procref ->
?dups:dup_spec ->
?path:bool ->
string -> ?argv0:string -> string list -> Pervasives.out_channel
stdin
.val open_program2 : ?procref:procref ->
?dups:dup_spec ->
?path:bool ->
string ->
?argv0:string -> string list -> Pervasives.in_channel * Pervasives.in_channel
stdout
and stderr
.val open_program3 : ?procref:procref ->
?dups:dup_spec ->
?path:bool ->
string ->
?argv0:string ->
string list ->
Pervasives.out_channel * Pervasives.in_channel * Pervasives.in_channel
stdin
, stdout
, and stderr
.val string_of_channel : Pervasives.in_channel -> string
val string_of_command : ?procref:procref -> string -> string
val string_of_program : ?procref:procref ->
?path:bool -> string -> ?argv0:string -> string list -> string
val open_string_in : string -> Pervasives.in_channel
in_channel
whose contents is a given string.val with_out_string : (Pervasives.out_channel -> 'a) -> 'a * string
stdout
and returns the return value of the
thunk and the collected output.
These functions correspond directly to those of the same name in the
Unix
structure. However, these directory handles are managed by
the garbage collected and thus closed if they become unreachable.
type
directory
val opendir : string -> directory
Unix.opendir
.val closedir : directory -> unit
Unix.closedir
.val readdir : directory -> string
Unix.readdir
.val rewinddir : directory -> unit
Unix.rewinddir
.module Dup:sig
..end