假设我有一个命令
`echo hello`
现在,我想将 STDOUT 和 STDERR 重定向到一个流,这样它就像 bash 中的2>&1
一样。我看到了两个 Julia 问题,但仍然不明白它在 Julia v.0.4 中应该如何工作。
https://github.com/JuliaLang/julia/issues/5344
https://github.com/JuliaLang/julia/issues/5349
请参阅pipeline
帮助,特别是:
run(pipeline(`echo hello`, stdout=STDOUT, stderr=STDOUT))
这会将两者重定向到同一流(进程STDOUT
(。这也可以是其他东西。
以下是您可以从 REPL 获得的帮助:
help?> pipeline
search: pipeline
pipeline(command; stdin, stdout, stderr, append=false)
Redirect I/O to or from the given command. Keyword arguments specify which
of the command's streams should be redirected. append controls whether file
output appends to the file. This is a more general version of the 2-argument
pipeline function. pipeline(from, to) is equivalent to pipeline(from,
stdout=to) when from is a command, and to pipeline(to, stdin=from) when from
is another kind of data source.
Examples:
run(pipeline(`dothings`, stdout="out.txt", stderr="errs.txt"))
run(pipeline(`update`, stdout="log.txt", append=true))
pipeline(from, to, ...)
Create a pipeline from a data source to a destination. The source and
destination can be commands, I/O streams, strings, or results of other
pipeline calls. At least one argument must be a command. Strings refer to
filenames. When called with more than two arguments, they are chained
together from left to right. For example pipeline(a,b,c) is equivalent to
pipeline(pipeline(a,b),c). This provides a more concise way to specify
multi-stage pipelines.
Examples:
run(pipeline(`ls`, `grep xyz`))
run(pipeline(`ls`, "out.txt"))
run(pipeline("out.txt", `grep xyz`))
此外,您应该至少升级到 Julia 0.5。 0.4 不再受支持,0.6 将很快发布。