I would like to run a bash command called samtools and assign its output to a variable that I can process with julia. Thus I made:
julia> r_file
"A3-T_F-AlnSrtDed.bam"
julia> r_locus
"chrV:254748988-254749089"
julia> query = run(pipeline(`samtools ... $r_file $r_locus`,
`grep -v @`, `cut -f 5`), String)
ERROR: MethodError: no method matching spawn_opts_inherit(::Type{String})
Closest candidates are:
spawn_opts_inherit() at process.jl:545
spawn_opts_inherit(::Tuple{Union{RawFD, FileRedirect, IO},Union{RawFD, FileRedirect, IO},Union{RawFD, FileRedirect, IO}}) at process.jl:541
spawn_opts_inherit(::Union{RawFD, FileRedirect, IO}) at process.jl:545
...
Stacktrace:
[1] #run#503(::Bool, ::Function, ::Base.OrCmds, ::Type) at ./process.jl:662
[2] run(::Base.OrCmds, ::Type) at ./process.jl:661
[3] top-level scope at none:0
julia> query = run(pipeline(`samtools ... $r_file $r_locus`,
`grep -v @`, `cut -f 5`))
21
Base.ProcessChain(Base.Process[Process(`samtools ... A3-T_F-AlnSrtDed.bam chrV:254748988-254749089`, ProcessExited(0)), Process(`grep -v @`, ProcessExited(0)), Process(`cut -f 5`, ProcessExited(0))], RawFD(0x00000000), RawFD(0x00000001), RawFD(0x00000002))
Essentially, if I don’t use String
, the command is assigned to query
but without String
I get an error.
What is the correct way to assign the shell’s output to a variable? This should be either a string (if there is a single output) or an array.