加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

shell – 如何在Julia中执行相当于2>&1的操作

发布时间:2020-12-16 01:49:53 所属栏目:安全 来源:网络整理
导读:假设我有一个命令 `echo hello` 现在,我想将STDOUT和STDERR重定向到单个流,因此它在bash中类似于2 1.我看到两个Julia问题,但仍然不明白它应该如何在Julia v.0.4中运行. https://github.com/JuliaLang/julia/issues/5344 https://github.com/JuliaLang/julia/
假设我有一个命令

`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

解决方法

请参阅管道帮助,特别是:

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将很快发布.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读