package containers

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

High-level Functions on top of Unix

Some useful functions built on top of Unix.

status: unstable

  • since 0.10
type 'a or_error = [
  1. | `Ok of 'a
  2. | `Error of string
]
type 'a gen = unit -> 'a option

Calling Commands

val escape_str : Buffer.t -> string -> unit

Escape a string so it can be a shell argument.

type call_result = < stdout : string ; stderr : string ; status : Unix.process_status ; errcode : int >
val call : ?bufsize:int -> ?stdin:[ `Gen of string gen | `Str of string ] -> ?env:string array -> ('a, Buffer.t, unit, call_result) Pervasives.format4 -> 'a

call cmd wraps the result of Unix.open_process_full cmd into an object. It reads the full stdout and stderr of the subprocess before returning.

  • parameter stdin

    if provided, the generator or string is consumed and fed to the subprocess input channel, which is then closed.

  • parameter bufsize

    buffer size used to read stdout and stderr

  • parameter env

    environment to run the command in

type line = string
type async_call_result = < stdout : line gen ; stderr : line gen ; stdin : line -> unit ; close_in : unit ; close_err : unit ; close_out : unit ; close_all : unit ; wait : Unix.process_status ; wait_errcode : int >

A subprocess for interactive usage (read/write channels line by line)

  • since 0.11
val async_call : ?env:string array -> ('a, Buffer.t, unit, async_call_result) Pervasives.format4 -> 'a

Spawns a subprocess, like call, but the subprocess's channels are line generators and line sinks (for stdin). if p is async_call "cmd", then p#wait waits for the subprocess to die. Channels can be closed independently.

  • since 0.11

Accessors

  • since 0.11
val stdout : < stdout : 'a.. > -> 'a
val stderr : < stderr : 'a.. > -> 'a
val status : < status : 'a.. > -> 'a
val errcode : < errcode : 'a.. > -> 'a

Infix Functions

module Infix : sig ... end
include module type of Infix
val (?|) : ('a, Buffer.t, unit, call_result) Pervasives.format4 -> 'a

Infix version of call

  • since 0.11
val (?|&) : ('a, Buffer.t, unit, async_call_result) Pervasives.format4 -> 'a

Infix version of async_call

  • since 0.11
OCaml

Innovation. Community. Security.