Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
open Belt.Result;
type options;
module Stdio: {
type t = pri string;
[@bs.inline "inherit"]
let inherit_: t;
[@bs.inline "ignore"]
let ignore: t;
[@bs.inline "pipe"]
let pipe: t;
let _array: array(t) => t;
let make: (t, t, t) => t;
} = {
type t = string;
[@bs.inline]
let inherit_ = "inherit";
[@bs.inline]
let ignore = "ignore";
[@bs.inline]
let pipe = "pipe";
external _array: array(t) => t = "%identity";
let make = (stdin, stdout, stderr) => [|stdin, stdout, stderr|] |> _array;
};
[@bs.obj]
external options:
(~cwd: string=?, ~stdio: Stdio.t=?, ~encoding: string=?, unit) => options =
"";
[@bs.module "child_process"]
external _execSync: (string, options) => string = "execSync";
let execSync = cmd =>
try (
Ok(
{
_execSync(
cmd,
options(
~encoding="utf-8",
~stdio=Stdio.(make(pipe, pipe, pipe)),
(),
),
)
|> String.trim;
},
)
) {
| e => Error(e)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment