Skip to content

Commit 3fc4e4d

Browse files
committed
Add usage example to README
1 parent 1806582 commit 3fc4e4d

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,54 @@
1111

1212
This package lets you capture subprocess `stdout` and `stderr` streams
1313
independently, resynthesizing and colorizing the streams appropriately.
14+
15+
## Installation
16+
17+
`OutputCollectors.jl` can be installed with [Julia built-in package
18+
manager](https://julialang.github.io/Pkg.jl/v1/). In a Julia session, after
19+
entering the package manager mode with `]`, run the command
20+
21+
```
22+
add OutputCollectors.jl
23+
```
24+
25+
## Usage
26+
27+
```julia
28+
julia> using OutputCollectors
29+
30+
julia> script = """
31+
#!/bin/sh
32+
echo 1
33+
sleep 1
34+
echo 2 >&2
35+
sleep 1
36+
echo 3
37+
sleep 1
38+
echo 4
39+
"""
40+
"#!/bin/sh\necho 1\nsleep 1\necho 2 >&2\nsleep 1\necho 3\nsleep 1\necho 4\n"
41+
42+
julia> oc = OutputCollector(`sh -c $script`; verbose = true);
43+
44+
julia> [22:42:30] 1
45+
[22:42:31] 2
46+
[22:42:32] 3
47+
[22:42:33] 4
48+
julia>
49+
50+
julia> merge(oc)
51+
"1\n2\n3\n4\n"
52+
53+
julia> merge(oc; colored = true)
54+
"1\n\e[31m2\n\e[39m3\n4\n"
55+
56+
julia> tail(oc; len = 2)
57+
"3\n4\n"
58+
59+
julia> collect_stdout(oc)
60+
"1\n3\n4\n"
61+
62+
julia> collect_stderr(oc)
63+
"2\n"
64+
```

0 commit comments

Comments
 (0)