调用外部程序时如何静音或重定向STDOUT?

Yau*_*ich 2 julia

按照文档我做:

julia> run(`echo hello`)
hello
Run Code Online (Sandbox Code Playgroud)

但实际上我并不需要那个输出

julia> run(`echo hello`)
Run Code Online (Sandbox Code Playgroud)

如何关闭它?我错过了什么?


process.jl 里面有一个名为Process的Type,但我现在还没想到如何生成它.

一些见解这里

julia> x = readall(`echo test`);

julia> x
"test\n"
Run Code Online (Sandbox Code Playgroud)

Yau*_*ich 5

在julia-0.4中,可以使用:

run(pipe(`echo test`, stdout="/dev/null", stderr="/dev/null"))
Run Code Online (Sandbox Code Playgroud)

甚至更多的跨平台

run(pipe(`echo test`, stdout=DevNull, stderr=DevNull))
Run Code Online (Sandbox Code Playgroud)

NB 管道未在julia-0.3中定义