首页 文章

在运行过程中将stderr重定向到stdout

提问于
浏览
-1

在cmd脚本中将stderr重定向到stdout的正式方法是在运行脚本之前使用 2>&1 选项:
例如 MyScript.cmd > output.txt 2>&1

有没有办法在运行过程中将stderr重定向到stdout?

(将我的代码推送到主函数并使用 2>&1 调用它对我来说不是解决方案,因为有不必要的副作用)

2 回答

  • 0

    也许您可以使用用户定义的句柄来区分错误流 .

    MyScript.cmd

    CommandICareAbout.exe 2>&3
    CommandICareAbout2.exe 2>&3
    CommandIDontCareAbout.exe
    

    用法

    MyScript.cmd > output.txt 2>&1 3> errors.txt
    

    您还可以将您不关心的命令静音,如下所示:

    CommandIDontCareAbout.exe 2>nul
    
  • 1

    由于@baruch在评论中已经链接,我的问题通过这种包装解决了

    2>&1 (
      command1
      command2
      .
      .
      EOF
    )
    

相关问题