module Fitting:Fittings represent processes, internal or external, that produce, consume, or transform data. This module provides basic constructors to make fittings out of both external UNIX commands and internalsig..end
Shtream functions, and fitting combinators
that combine fittings in a variety of ways.
This module includes both functions specialized to shtreams of
Line.t and a functor for creating a structure specialized for
sthreams of other types.
type ('a -> 'b) t
'a and produces
values of type 'b.type'aelem ='a LineShtream.elem
typeinitial =LineShtream.initial
AnyShtream.ELEM.elem at LineShtream
This is the type of elements that fittings know how to write to
external processes.
type'ashtream ='a LineShtream.t
AnyShtream.ELEM.initial at LineShtream
This is the parameter to the type Fitting.elem for specifying
the type of elements that fittings know how to read from
external processes. That is, fittings constructed from external
processes produce values of type initial elem.
type'acoshtream ='a LineShtream.co_t
LineShtream.tLineShtream.co_ttypeprocref =Channel.procref
Channel.procreftypetext =initial elem
val (-|) : ('a -> 'b) t -> ('b -> 'c) t -> ('a -> 'c) tval pipe : ('a -> 'b) t -> ('b -> 'c) t -> ('a -> 'c) tFitting.(-|)
Producers are useful for starting off pipelines.
val from_file : string -> ('a -> text) tfrom_file file -| fitting is like % fitting < file
val from_null : ('a -> text) tfrom_null -| fitting is like % fitting < /dev/null
val from_gen : Channel.dup_in_source -> ('a -> text) tChannel.dup_in_source.val from_shtream : 'a shtream -> ('b -> 'a) t
Consumers are useful for ending pipelines.
val to_file : ?clobber:Channel.clobber_spec -> string -> ('a elem -> 'b) tChannel.clobber_spec for open modes.
fitting -| to_file file is like % fitting > file
val to_null : ('a elem -> 'b) tfitting -| to_null is like % fitting > /dev/null
val to_stderr : ('a elem -> 'b) tfitting -| to_stderr is like % fitting >&2
val to_gen : Channel.dup_out_source -> ('a elem -> 'b) tChannel.dup_out_source.val to_coshtream : 'a coshtream -> ('a -> 'b) tval command : string -> ('a elem -> text) tChannel.open_command.val program : ?path:bool ->
string ->
?argv0:string -> string list -> ('a elem -> text) tChannel.open_program.val thunk : (unit -> unit) -> ('a elem -> text) tval sed : ('a -> 'b) -> ('a -> 'b) tval grep : ('a -> bool) -> ('a -> 'a) tval trans : ('a shtream -> 'b shtream) -> ('a -> 'b) tval sed_string : (string -> 'a) -> ('b elem -> 'a) tFitting.sed with a lift from strings.val grep_string : (string -> bool) -> ('a elem -> 'a elem) tval (/</) : (text -> 'a) t ->
Channel.dup_spec -> (text -> 'a) tfitting /</ dups
performs the redirections specifed by dups for the extent
of fitting. For example,
fitting /</ [ 4 %<& 0; 0 %< "file" ] is like
% fitting 4<&0 <file
val redirect_in : Channel.dup_spec ->
(text -> 'a) t -> (text -> 'a) tFitting.(/</)val (/>/) : ('a -> 'b elem) t ->
Channel.dup_spec -> ('a -> 'b elem) tfitting />/ dups
performs the redirections specifed by dups for the extent
of fitting. For example,
fitting />/ [ 2 %>& 1 ] is like
% fitting 2>&1
val redirect_out : Channel.dup_spec ->
('a -> 'b elem) t -> ('a -> 'b elem) tFitting.(/>/)val (^>>=) : ('a -> 'b) t ->
(Proc.status -> ('a -> 'b) t) -> ('a -> 'b) t
The exit code of external processes is the actual exit code as
reported by Proc.wait. The exit code of a shtream is 0 unless
the shtream terminates by calling Shtream.fail_with n, in which
case the code in n. Or, Fitting.yield can return an exit code
directly.
val seq : ('a -> 'b) t ->
(Proc.status -> ('a -> 'b) t) -> ('a -> 'b) tFitting.(^>>=)val (^>>) : ('a -> 'b) t -> ('a -> 'b) t -> ('a -> 'b) t a ^>> b is exactly a ^>>= fun _ -> b .
This is like ; in the shell.val (&&^) : ('a -> 'b) t -> ('a -> 'b) t -> ('a -> 'b) t&& in the shell.val (||^) : ('a -> 'b) t -> ('a -> 'b) t -> ('a -> 'b) t|| in the shell.val (~>>) : ('a -> 'b) t list -> ('a -> 'b) tFitting.(^>>).val (~&&) : ('a -> 'b) t list -> ('a -> 'b) tFitting.(&&^).
Terminates the sequence when any component fails.val (~||) : ('a -> 'b) t list -> ('a -> 'b) tFitting.(||^).
Terminates the sequence when any component succeeds.val commands : string list -> (text -> text) tval yield : Proc.status -> ('a -> 'b) tval caml : (unit -> ('a -> 'b) t) -> ('a -> 'b) tFitting.caml constructs a new fitting that,
when run, forces the thunk and runs the resulting fitting.
This allows for Ocaml side-effects at arbitrary points during a
fitting.val (^&=) : (text -> 'a elem) t ->
(Proc.t -> ('b -> 'c) t) -> ('b -> 'c) t bg ^&= fg runs bg
in the background, passed its Proc.t to fg, and runs
the fitting returned by fg (in the foreground).
Notice that the bg must have input type Fitting.text; it will
construct its own input shtream from the standard input.
val par : (text -> 'a elem) t ->
(Proc.t -> ('b -> 'c) t) -> ('b -> 'c) tFitting.(^&=)val (^&) : (text -> 'a elem) t ->
('b -> 'c) t -> ('b -> 'c) tProc.t. This
backgrounds its first argument and then continues with its second
argument in the foreground.val run_source : (text -> 'a) t -> 'a shtreamval run_sink : ('a -> 'b elem) t -> 'a coshtreamval run_list : (text -> 'a) t -> 'a listval run_shtream : ('a -> 'b) t -> 'a shtream -> 'b shtreamval run_in : ?procref:procref ->
(text -> 'a elem) t -> Pervasives.in_channelin_channel. The fitting
will take its input from the standard input. If ?procref is
provided, the Proc.t of the child process will be stashed.val run_out : ?procref:procref ->
(text -> 'a elem) t -> Pervasives.out_channelout_channel. The fitting
will send its output from the standard output. If ?procref is
provided, the Proc.t of the child process will be stashed.val run_backquote : ?procref:procref ->
(text -> 'a elem) t -> string?procref.val run_bg : (text -> 'a elem) t -> Proc.tProc.t.
The fitting will take its input from the standard input and send
its output to the standard output.val run : (text -> 'a elem) t -> Proc.statusFitting.elem conversions provided to the
Fitting.Make functor by AnyShtream.ELEM. The conversion
AnyShtream.ELEM.string_of or AnyShtream.ELEM.of_string
is completely applied for each of these conversions, so no state
(should there be any) is retained in between calls.val string_of_elem : 'a elem -> stringval elem_of_string : string -> textval int_of_elem : 'a elem -> intval elem_of_int : int -> textval char_of_elem : 'a elem -> charval elem_of_char : char -> textval float_of_elem : 'a elem -> floatval elem_of_float : float -> textval bool_of_elem : 'a elem -> boolval elem_of_bool : bool -> textmodule type SHTREAM = AnyShtream.ANYSHTREAMFitting.Make.
module type FITTING =sig..end
Fitting.Make.
module Make: