Hi,
I would like to recover a string containing the status of a given package (v.2.2.2 in the example) but I am only able to print it out
julia> Pkg.status("CuArrays")
Project BTL v0.1.0
Status `~/Project/BTL.jl/Project.toml`
[3a865a2d] CuArrays v2.2.2
Is there a simple way to do it ?
JLDC
#2
Hi!
Would something along those lines work for you?
original_stdout = stdout
(rd, wr) = redirect_stdout()
Pkg.status("CuArrays")
s = readline(rd)
redirect_stdout(original_stdout)
println(s)
See: https://stackoverflow.com/questions/54599148/in-julia-1-0-how-do-i-get-strings-using-redirect-stdout
1 Like
Thanks a lot, this will do.
I was wondering if I missed some obvious solution.
Actually this only returns the first line.
I wonder why there is no IO first argument as it is often the case with Julia functions.
JLDC
#5
In that case you can just use readlines(rd)
to get an array of strings.
But after a bit of tinkering around, I think this here suits you better than my solution above:
io = IOBuffer(read=true, write=true)
Pkg.status("CuArrays", io=io)
s = String(take!(io))
println(s)
1 Like
Yes, much nicer !
I wonder why the help does not mention the io argument
help?> Pkg.status
Pkg.status([pkgs...]; mode::PackageMode=PKGMODE_PROJECT, diff::Bool=false)
...
Than you again !
oheil
#7
It is something general, not only for status()
2 Likes