gpt4 book ai didi

powershell - Powershell将stderr和stdout重定向到两个不同的位置

转载 作者:行者123 更新时间:2023-12-04 17:31:15 26 4
gpt4 key购买 nike

如何重定向

  • stderr到日志文件
  • stdout到对象

  • 我看过的东西:
    >>2>>仅重定向到file。
    -RedirectStandardOutput-RedirectStandardError仅再次重定向到文件。
    | Out-File无法重定向stderr。
    | Tee-Object同样的问题。

    最佳答案

    尽管语法不是最直观的,但将stdoutstderr输出流连接起来就像PetSerAl注释一样。
    2>&1的语法怪异,意味着stderr(流2)将被添加到stdout(流1)中。由于这实际上并不是您想要的,因此请尝试将MS页面中的另一个示例改编为Powershell:

    Or, you can redirect the output to one place, and the errors to another.

    dir file.xxx > output.msg 2> output.err



    因此,
    $ret = myCommand 2> errors.log

    应该在日志文件中发送错误,而在 $ret变量中发送非错误。

    关于powershell - Powershell将stderr和stdout重定向到两个不同的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45071557/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com