Skip to content

Instantly share code, notes, and snippets.

@cem2ran
Created November 24, 2019 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cem2ran/0d02a658adf81fded8f1f1bf4879b571 to your computer and use it in GitHub Desktop.
Save cem2ran/0d02a658adf81fded8f1f1bf4879b571 to your computer and use it in GitHub Desktop.
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