Command line 如何运行从julia接收输入的外部程序
我有一个非常基本的问题: 我有一个文件,我需要为里面的每个单词运行一个命令。假设我现在使用的单词是“example_word”,我需要运行的命令如下:Command line 如何运行从julia接收输入的外部程序,command-line,julia,Command Line,Julia,我有一个非常基本的问题: 我有一个文件,我需要为里面的每个单词运行一个命令。假设我现在使用的单词是“example_word”,我需要运行的命令如下: readall(run(pipeline(`echo example_word`,`flookup model.foma`)) 不幸的是,我无法从repl获取此命令的输出。我在网上搜索,建议使用readstring。当我尝试它时,我得到了以下错误: julia> read(pipeline(`echo example_word`,`flo
readall(run(pipeline(`echo example_word`,`flookup model.foma`))
不幸的是,我无法从repl获取此命令的输出。我在网上搜索,建议使用readstring。当我尝试它时,我得到了以下错误:
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
或者(如@DanGetz所建议的)
只要用您想要使用的命令替换cat
,我的计算机上没有它
我希望将来您可能会意识到,通过仔细查看错误消息,您不需要为readstring
提供String
参数:)
或者(如@DanGetz所建议的)
只要用您想要使用的命令替换cat
,我的计算机上没有它
我希望将来您可能会意识到,通过仔细查看错误消息,您不需要为readstring
提供String
参数:)
x=read(管道(`echo example\u word`,`flookup model.foma`))、String)
或x=readstring(管道())
,具体取决于版本。您可能需要解析(Int,x)
later@DanGetz他们都没有工作。请注意,readstring
版本没有String
参数x=read(管道(`echo example\u word`、`flookup model.foma`)、String)
或x=readstring(管道())
,具体取决于版本。您可能需要解析(Int,x)
later@DanGetz他们都没有工作。我相应地编辑了这个问题。注意readstring
版本没有String
参数+1。值得指出的是,readstring(x)
正在被弃用,取而代之的是未来谷歌的read(x,String)
:)+1。值得指出的是,readstring(x)
正在被弃用,取而代之的是未来谷歌的read(x,String)
)
String(read(pipeline(`echo example_word`,`cat`)))
readstring(pipeline(`echo example_word`,`cat`))
ERROR: MethodError: no method matching readstring(::Base.OrCmds, ::Type{String})
Closest candidates are:
readstring(::Base.AbstractCmd) at process.jl:581