-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.carp
More file actions
32 lines (27 loc) · 1.6 KB
/
Copy pathexample.carp
File metadata and controls
32 lines (27 loc) · 1.6 KB
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
(load "./subprocess.carp")
(defn-do main []
; Prints all to stdout/stderr
(ignore (Subprocess.cmd (zero) &[@"echo" @"subprocess"]))
; Saves stdout and stderr as strings
(let-do [res (Subprocess.cmd (SubprocessOptions.spp)
&[@"sh" @"-c" @"printf 'this is stderr' 1>&2; printf 'this is stdout'; exit 42"])]
(println* "out >>> " (Maybe.unsafe-from @(SubprocessRes.out &res)))
(println* "err >>> " (Maybe.unsafe-from @(SubprocessRes.err &res)))
(println* "exit-code >>> " (SubprocessRes.exit-code &res)))
(println* "after")
; Combines stdout and stderr as string
(let-do [res (Subprocess.cmd (SubprocessOptions.spo)
&[@"sh" @"-c" @"printf 'this is stderr' 1>&2; printf 'this is stdout'"])]
(println* "combined >>> " (Maybe.unsafe-from @(SubprocessRes.out &res)))
(println* "exit-code >>> " (SubprocessRes.exit-code &res)))
; Manually pipe one command into another
(let [echo (Subprocess.call (SubprocessOptions.sps) &[@"echo" @"wow"])
out-pipe (Maybe.unsafe-from @(Subprocess.out &echo))]
(ignore (Subprocess.cmd (SubprocessOptions.iss out-pipe)
&[@"cat"])))
; Pipe multiple commands together
(let-do [res (Subprocess.collect (Subprocess.pipe &[[@"echo" @"are"]
[@"awk" @"{print \"you>\" $0 \"<surrounded\"}"]
[@"tr" @"<>" @"><"]]))]
(println* "out >>> " (Maybe.unsafe-from @(SubprocessRes.out &res)))
(println* "exit-code >>> " (SubprocessRes.exit-code &res))))