Created
November 24, 2019 15:27
-
-
Save cem2ran/0d02a658adf81fded8f1f1bf4879b571 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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