OutputCollectors.jl

Capture subprocess stdout and stderr streams independently, resynthesizing and colorizing the streams appropriately
Author JuliaPackaging
Popularity
8 Stars
Updated Last
1 Year Ago
Started In
June 2020

OutputCollectors.jl

CI

Coverage Status codecov

This package lets you capture subprocess stdout and stderr streams independently, resynthesizing and colorizing the streams appropriately.

Installation

OutputCollectors.jl can be installed with Julia built-in package manager. In a Julia session, after entering the package manager mode with ], run the command

add OutputCollectors.jl

Usage

julia> using OutputCollectors

julia> script = """
       #!/bin/sh
       echo 1
       sleep 1
       echo 2 >&2
       sleep 1
       echo 3
       sleep 1
       echo 4
       """
"#!/bin/sh\necho 1\nsleep 1\necho 2 >&2\nsleep 1\necho 3\nsleep 1\necho 4\n"

julia> oc = OutputCollector(`sh -c $script`; verbose = true);

julia> [22:42:30] 1
[22:42:31] 2
[22:42:32] 3
[22:42:33] 4
julia>

julia> merge(oc)
"1\n2\n3\n4\n"

julia> merge(oc; colored = true)
"1\n\e[31m2\n\e[39m3\n4\n"

julia> tail(oc; len = 2)
"3\n4\n"

julia> collect_stdout(oc)
"1\n3\n4\n"

julia> collect_stderr(oc)
"2\n"

Required Packages

No packages found.