mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
add methods and accessors to CCUnix
This commit is contained in:
parent
78fb6c53f2
commit
57f65bd140
2 changed files with 24 additions and 1 deletions
|
|
@ -122,7 +122,9 @@ type async_call_result =
|
||||||
close_in:unit; (* close stdin *)
|
close_in:unit; (* close stdin *)
|
||||||
close_err:unit;
|
close_err:unit;
|
||||||
close_out:unit;
|
close_out:unit;
|
||||||
|
close_all:unit; (* close all 3 channels *)
|
||||||
wait:Unix.process_status; (* block until the process ends *)
|
wait:Unix.process_status; (* block until the process ends *)
|
||||||
|
wait_errcode:int; (* block until the process ends, then extract errcode *)
|
||||||
>
|
>
|
||||||
|
|
||||||
let async_call ?(env=Unix.environment()) cmd =
|
let async_call ?(env=Unix.environment()) cmd =
|
||||||
|
|
@ -132,7 +134,7 @@ let async_call ?(env=Unix.environment()) cmd =
|
||||||
(fun buf ->
|
(fun buf ->
|
||||||
let cmd = Buffer.contents buf in
|
let cmd = Buffer.contents buf in
|
||||||
let oc, ic, errc = Unix.open_process_full cmd env in
|
let oc, ic, errc = Unix.open_process_full cmd env in
|
||||||
object
|
object (self)
|
||||||
method stdout () =
|
method stdout () =
|
||||||
try Some (input_line oc)
|
try Some (input_line oc)
|
||||||
with End_of_file -> None
|
with End_of_file -> None
|
||||||
|
|
@ -143,10 +145,17 @@ let async_call ?(env=Unix.environment()) cmd =
|
||||||
method close_in = close_out ic
|
method close_in = close_out ic
|
||||||
method close_out = close_in oc
|
method close_out = close_in oc
|
||||||
method close_err = close_in errc
|
method close_err = close_in errc
|
||||||
|
method close_all = close_out ic; close_in oc; close_in errc; ()
|
||||||
method wait = Unix.close_process_full (oc, ic, errc)
|
method wait = Unix.close_process_full (oc, ic, errc)
|
||||||
|
method wait_errcode = int_of_process_status self#wait
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
let stdout x = x#stdout
|
||||||
|
let stderr x = x#stderr
|
||||||
|
let status x = x#status
|
||||||
|
let errcode x = x#errcode
|
||||||
|
|
||||||
module Infix = struct
|
module Infix = struct
|
||||||
let (?|) fmt = call fmt
|
let (?|) fmt = call fmt
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,10 @@ type async_call_result =
|
||||||
close_in:unit; (* close stdin *)
|
close_in:unit; (* close stdin *)
|
||||||
close_err:unit;
|
close_err:unit;
|
||||||
close_out:unit;
|
close_out:unit;
|
||||||
|
close_all:unit; (* close all 3 channels *) (** @since NEXT_RELEASE *)
|
||||||
wait:Unix.process_status; (* block until the process ends *)
|
wait:Unix.process_status; (* block until the process ends *)
|
||||||
|
wait_errcode:int; (* block until the process ends, then extract errcode *)
|
||||||
|
(** @since NEXT_RELEASE *)
|
||||||
>
|
>
|
||||||
(** A subprocess for interactive usage (read/write channels line by line)
|
(** A subprocess for interactive usage (read/write channels line by line)
|
||||||
@since NEXT_RELEASE *)
|
@since NEXT_RELEASE *)
|
||||||
|
|
@ -96,6 +99,17 @@ val async_call : ?env:string array ->
|
||||||
to die. Channels can be closed independently.
|
to die. Channels can be closed independently.
|
||||||
@since NEXT_RELEASE *)
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
(** {2 Accessors}
|
||||||
|
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val stdout : < stdout : 'a; .. > -> 'a
|
||||||
|
val stderr : < stderr : 'a; .. > -> 'a
|
||||||
|
val status : < status : 'a; .. > -> 'a
|
||||||
|
val errcode : < errcode : 'a; .. > -> 'a
|
||||||
|
|
||||||
|
(** {2 Infix Functions} *)
|
||||||
|
|
||||||
module Infix : sig
|
module Infix : sig
|
||||||
val (?|) : ('a, Buffer.t, unit, call_result) format4 -> 'a
|
val (?|) : ('a, Buffer.t, unit, call_result) format4 -> 'a
|
||||||
(** Infix version of {!call}
|
(** Infix version of {!call}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue