用法一
redirect_stdio(;stdin=stdin, stderr=stderr, stdout=stdout)重定向流的子集stdin、stderr、stdout。每个参数必须是 IOStream 、 TTY 、 Pipe 、套接字或 devnull 。
Julia 1.7
redirect_stdio 需要 Julia 1.7 或更高版本。
用法二
redirect_stdio(f; stdin=nothing, stderr=nothing, stdout=nothing)重定向流的子集 stdin 、 stderr 、 stdout ,调用 f() 并恢复每个流。
每个流的可能值为:
- nothing指示不应重定向流。
- path::AbstractString将流重定向到位于- path的文件。
- io和- IOStream、- TTY、- Pipe、套接字或- devnull。
例子
julia> redirect_stdio(stdout="stdout.txt", stderr="stderr.txt") do
           print("hello stdout")
           print(stderr, "hello stderr")
       end
julia> read("stdout.txt", String)
"hello stdout"
julia> read("stderr.txt", String)
"hello stderr"边案例
可以将相同的参数传递给 stdout 和 stderr :
julia> redirect_stdio(stdout="log.txt", stderr="log.txt", stdin=devnull) do
    ...
end但是,不支持传递同一文件的两个不同说明符。
julia> io1 = open("same/path", "w")
julia> io2 = open("same/path", "w")
julia> redirect_stdio(f, stdout=io1, stderr=io2) # not suppored此外 stdin 参数可能与 stdout 或 stderr 的说明符不同。
julia> io = open(...)
julia> redirect_stdio(f, stdout=io, stdin=io) # not supportedJulia 1.7
redirect_stdio 需要 Julia 1.7 或更高版本。
相关用法
- Julia reduce方法用法及代码示例
- Julia rem用法及代码示例
- Julia readchomp用法及代码示例
- Julia readuntil用法及代码示例
- Julia replace!用法及代码示例
- Julia real方法用法及代码示例
- Julia readlines用法及代码示例
- Julia replace()用法及代码示例
- Julia retry用法及代码示例
- Julia read用法及代码示例
- Julia reverseind用法及代码示例
- Julia reim用法及代码示例
- Julia repeat方法用法及代码示例
- Julia readline用法及代码示例
- Julia repeat用法及代码示例
- Julia repr方法用法及代码示例
- Julia reverse!用法及代码示例
- Julia reshape用法及代码示例
- Julia replace方法用法及代码示例
- Julia repeat()用法及代码示例
- Julia reverse方法用法及代码示例
- Julia resize!用法及代码示例
- Julia readeach用法及代码示例
- Julia reverse()用法及代码示例
- Julia rest用法及代码示例
注:本文由纯净天空筛选整理自julialang.org 大神的英文原创作品 Base.redirect_stdio — Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
