Module Jupyter_notebook.Process

Operations on subprocesses

type process_status = Unix.process_status =
  1. | WEXITED of int
  2. | WSIGNALED of int
  3. | WSTOPPED of int
val pp_process_status : Ppx_deriving_runtime.Format.formatter -> process_status -> Ppx_deriving_runtime.unit
val show_process_status : process_status -> Ppx_deriving_runtime.string
type t = {
  1. exit_status : Unix.process_status;
  2. stdout : string option;
  3. stderr : string option;
}

The type of execution results of subprocesses.

val pp : Ppx_deriving_runtime.Format.formatter -> t -> Ppx_deriving_runtime.unit
val show : t -> Ppx_deriving_runtime.string
type capture_stderr_type = [
  1. | `No
  2. | `Yes
  3. | `Redirect_to_stdout
]
exception Execution_failure of t

Command bindings

val system : ?check:bool -> ?capture_stdout:bool -> ?capture_stderr:capture_stderr_type -> ?interval:float -> string -> string list -> t

system prog args is a rich version of Unix.system and Sys.command in the standard library of OCaml.

Example:

system "ocaml" ["ocaml"; "-vnum"]
  • parameter check

    raises an execption when a process fails (default = true)

  • parameter capture_stdout

    default = true

  • parameter capture_stderr

    default = `No

  • parameter interval

    timeout of Unix.select for waiting IO (default = 0.1 seconds)

  • parameter prog

    The path or the name of an executable file. If not a path, the environment variable $PATH is used for finding the file.

  • parameter args

    The list of arguments given to a command.

  • returns

    an execution result of a subprocess.

  • since 2.8.0
val pwd : unit -> string

pwd () returns a path to the current directory.

This is an alias of Unix.getcwd.

  • since 2.8.0
val cd : string -> unit

cd path changes the current directory.

This is an alias of Unix.chdir.

  • since 2.8.0
val ls : ?check:bool -> ?capture_stdout:bool -> ?capture_stderr:capture_stderr_type -> ?interval:float -> ?args:string list -> string list -> t

ls ?check ?capture_stdout ?capture_stderr ?interval ?args paths shows a list of files in paths.

  • since 2.8.0
val rm : ?check:bool -> ?capture_stdout:bool -> ?capture_stderr:capture_stderr_type -> ?interval:float -> ?args:string list -> string list -> t

rm ?check ?capture_stdout ?capture_stderr ?interval ?args paths removes files in paths.

  • since 2.8.0
val cp : ?check:bool -> ?capture_stdout:bool -> ?capture_stderr:capture_stderr_type -> ?interval:float -> ?args:string list -> string -> string -> t

cp ?check ?capture_stdout ?capture_stderr ?interval ?args src_path dest_path copys a file or a directory from src_path into dest_path.

  • since 2.8.0
val mv : ?check:bool -> ?capture_stdout:bool -> ?capture_stderr:capture_stderr_type -> ?interval:float -> ?args:string list -> string -> string -> t

mv ?check ?capture_stdout ?capture_stderr ?interval ?args src_path dest_path moves a file or a directory from src_path into dest_path.

  • since 2.8.0
val sh : ?check:bool -> ?capture_stdout:bool -> ?capture_stderr:capture_stderr_type -> ?interval:float -> ?args:string list -> string -> t

sh ?check ?capture_stdout ?capture_stderr ?interval ?args script evaluates a given code script by sh command.

Example:

sh {|
set -eu

VAR=hello
echo "$VAR"|}
  • since 2.8.0
val zsh : ?check:bool -> ?capture_stdout:bool -> ?capture_stderr:capture_stderr_type -> ?interval:float -> ?args:string list -> string -> t

zsh ?check ?capture_stdout ?capture_stderr ?interval ?args script evaluates a given code script by zsh command.

  • since 2.8.0
val bash : ?check:bool -> ?capture_stdout:bool -> ?capture_stderr:capture_stderr_type -> ?interval:float -> ?args:string list -> string -> t

bash ?check ?capture_stdout ?capture_stderr ?interval ?args script evaluates a given code script by bash command.

  • since 2.8.0
val python2 : ?check:bool -> ?capture_stdout:bool -> ?capture_stderr:capture_stderr_type -> ?interval:float -> ?args:string list -> string -> t

python2 ?check ?capture_stdout ?capture_stderr ?interval ?args script evaluates a given code script by python2 command.

  • since 2.8.0
val python3 : ?check:bool -> ?capture_stdout:bool -> ?capture_stderr:capture_stderr_type -> ?interval:float -> ?args:string list -> string -> t

python3 ?check ?capture_stdout ?capture_stderr ?interval ?args script evaluates a given code script by python3 command.

  • since 2.8.0
val ruby : ?check:bool -> ?capture_stdout:bool -> ?capture_stderr:capture_stderr_type -> ?interval:float -> ?args:string list -> string -> t

ruby ?check ?capture_stdout ?capture_stderr ?interval ?args script evaluates a given code script by ruby command.

  • since 2.8.0
val perl : ?check:bool -> ?capture_stdout:bool -> ?capture_stderr:capture_stderr_type -> ?interval:float -> ?args:string list -> string -> t

perl ?check ?capture_stdout ?capture_stderr ?interval ?args script evaluates a given code script by perl command.

  • since 2.8.0

Capturing

val capture_in_process : ?check:bool -> ?capture_stdout:bool -> ?capture_stderr:capture_stderr_type -> ?interval:float -> (unit -> 'a) -> t

capture_in_process ?check ?capture_stdout ?capture_stderr ?interval f captures data output to stdout/stderr during execution of a function f.

NOTE: capture_in_process creates a new subprocess and evaluates f in the subprocess. Therefore f cannot modify memory of the parent process. For example, the following snippet results in 0, not 42.

let r = ref 0 in
let _ = capture_in_process (fun () -> r := 42) in
!r (* 0, not 42 *)
  • parameter check

    raises an execption when a process fails (default = true)

  • parameter capture_stdout

    default = true

  • parameter capture_stderr

    default = `No

  • parameter interval

    timeout of Unix.select for waiting IO (default = 0.1 seconds)

  • returns

    an execution result of a subprocess.

  • since 2.8.0