package spotlib

  1. Overview
  2. Docs

Command invocation

Typical usage is:

starter |> scanner , for example shell "ls /" |> print

or

starter |> scanner |> result_checker , for example shell "ls /" |> get_stdout |> must_exist_with ~name:"ls /" 0

Starter

Starters invoke processes and returns a value of 'st t. You do not need to care about 'st: it is determined by a output scanner.

type 'st t
val shell : string -> 'st t

Execute a shell command using /bin/sh

val execvp : string list -> 'st t

Same as shell_command but it takes the command and arguments as a list of string, then directly executed by Unix.execvp.

Output scanner

Output scanner takes the result of a starter and scans its stdout+stderr output. After all the stdout+stderr outputs are sent to the scanner, it returns the final result of the scan and the process status

type 'a result = Unix.process_status * 'a
val fold : 'st t -> init:'st -> f:('st -> ([ `Out | `Err ] * [ `Read of string | `EOF ]) -> 'st) -> 'st result

Generic scanner

val iter : unit t -> f:(([ `Out | `Err ] * [ `Read of string | `EOF ]) -> unit) -> unit result

Iteration over stdout+stderr outputs

val print : ?prefix:string -> unit t -> unit result

Output to stdout and stderr of the command are printed to stdout and stderr resp.ly.

val ignore_output : unit t -> unit result

Completely ignore the outputs

val get_stdout : string list t -> string list result

Gather stdout lines. Stderr outputs are printed to stderr.

val get_all : string list t -> string list result

Gather stdout and stderr lines.

Result tools

val fail : ?name:string -> 'res result -> 'no_return
val from_exit : ?name:string -> 'res result -> int * 'res
val must_exit_with : ?name:string -> int -> 'res result -> 'res
val should_exit_with : int -> 'res result -> ('res, Unix.process_status * 'res) Vresult.t
OCaml

Innovation. Community. Security.