How to capture run/pipeline output


#1

As an example, the following code has 1 1 4 printed in the console. How do I capture that into a string variable?

run(pipeline(`echo 123`, `wc`))

#2
s = readlines(pipeline(`echo 123`, `wc`))

or

s = readstring(pipeline(`echo 123`, `wc`))

#3

There’s yet another solution in the docs:

read(pipeline(`echo 123`, `wc`), String)

This is equivalent to the readstring example.


#4

Cool! :slight_smile:

And you could read lines asynchronously too! :scream:

julia> import Dates
julia> r = eachline(```
       julia -e """
          for i in 1:3 
            sleep(1)
            println('*') 
          end"""
       ```);
julia> for i in r 
         println("$i $(Dates.now(Dates.UTC))")
       end;
       
* 2018-10-11T10:43:28.4
* 2018-10-11T10:43:29.402
* 2018-10-11T10:43:30.404