如何运行外部程序,该程序通过朱莉娅的回声获取其输入



我有一个非常基本的问题:

我有一个文件,我需要为里面的每个单词运行一个命令。假设我现在的单词是"example_word"我需要运行的命令如下:

readall(run(pipeline(`echo example_word`,`flookup model.foma`))

不幸的是,我无法从 repl 获取此命令的输出。我在网上搜索,建议阅读字符串。当我尝试它时,我收到以下错误:

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
String(read(pipeline(`echo example_word`,`cat`)))

或(如@DanGetz建议(

readstring(pipeline(`echo example_word`,`cat`))

只需将cat替换为您要使用的命令,我的计算机上没有它。

我将来您可能已经意识到,您不需要通过仔细查看错误消息来readstringString参数:)

ERROR: MethodError: no method matching readstring(::Base.OrCmds, ::Type{String})
Closest candidates are:
readstring(::Base.AbstractCmd) at process.jl:581

最新更新