1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
open Js_of_ocaml
open Js
class type stream =
object
method fd: int readonly_prop
end
class type process =
object
method argv: (js_string t) js_array t readonly_prop
method cwd: js_string t meth
method exit: int -> 'a meth
method nextTick: (unit -> unit) callback -> unit meth
method stdin: stream t readonly_prop
method stdout: stream t readonly_prop
method stderr: stream t readonly_prop
end
let process: process t = Unsafe.eval_string "require('process')"
let next_tick (k:unit -> unit): unit =
process##nextTick
(wrap_callback k)
let exit (code:int): 'a =
Printf.printf "exiting with code %d\n" code;
process##exit code
let command_line: string array =
let arr = to_array process##.argv in
let len = Array.length arr in
assert (0 < len);
Array.map to_string (Array.sub arr 1 (len - 1))
let current_working_directory (_:unit): string =
to_string process##cwd