我有一个非常基本的问题:
我有一个文件,我需要为里面的每个单词运行一个命令。让我们假设我现在拥有的这个词是" example_word"我需要运行的命令如下:
readall(run(pipeline(`echo example_word`,`flookup model.foma`))
不幸的是,我无法从repl获取此命令的输出。我在网上搜索,推荐使用readtring。当我尝试它时,我得到以下错误:
julia> read(pipeline(`echo example_word`,`flookup model.foma`),String)
ERROR: MethodError: no method matching read(::Base.OrCmds, ::Type{String})
Closest candidates are:
read(::AbstractString, ::Any...) at io.jl:109
read{T}(::IO, ::Type{T}, ::Int64, ::Int64...) at io.jl:235
read{T}(::IO, ::Type{T}, ::Integer, ::Integer...) at io.jl:236
...
julia> readstring(pipeline(`echo example_word`,`flookup model.foma`),String)
ERROR: MethodError: no method matching readstring(::Base.OrCmds, ::Type{String})
Closest candidates are:
readstring(::Base.AbstractCmd) at process.jl:581
readstring(::Base.AbstractCmd, ::Union{Base.FileRedirect,IO,RawFD}) at process.jl:581
答案 0 :(得分:2)
String(read(pipeline(`echo example_word`,`cat`)))
或(如@DanGetz建议的那样)
readstring(pipeline(`echo example_word`,`cat`))
只需将cat
替换为您要使用的命令,我的计算机上没有它。
我未来您可能已经意识到您不需要通过查看错误消息来readstring
String
ERROR: MethodError: no method matching readstring(::Base.OrCmds, ::Type{String})
Closest candidates are:
readstring(::Base.AbstractCmd) at process.jl:581
参数:)
[ngClass]