如何在Julia中执行与2>&1等效的操作

4
1个回答

9

请查看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即将发布。


你是如何从REPL获取帮助的? - m33lky
在 REPL 提示符下输入 ? - Fengyang Wang
请查看Suppressor。这是一个用于Julia的宏,可用于抑制和/或捕获输出(STDOUT)、警告(STDERR)或同时抑制两个流的工具。 - ShpielMeister

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接