【问题标题】:Command line output not redirecting to file.命令行输出未重定向到文件。
【发布时间】:2013-05-22 05:24:26
【问题描述】:

很简单:

打开控制台,然后输入

mkdir abc > output.txt

它会创建一个名为 output.txt 的文件,该文件是空的。

现在重复

mkdir abc > output.txt

这显示在命令窗口中:

A subdirectory or file abc already exists

但不将其输出到 txt。

为什么?

【问题讨论】:

    标签: windows command-line


    【解决方案1】:

    您正在将标准输出重定向到您的文件;错误通常在标准错误上报告,标准错误是不同的输出流。要重定向标准错误,您可以这样做:

    mkdir abc 2> output.txt
    

    或者,如果您想合并两个流并将它们定向在一起:

    mkdir abc 2>&1 >output.txt
    

    更多详情here.

    【讨论】:

      【解决方案2】:

      这将静默创建一个文件夹,无论它是否存在。

      mkdir abc 2>nul
      

      【讨论】:

        【解决方案3】:

        因为第二次调用的 mkdir 的输出转到 stderr 而不是 stdout。

        【讨论】:

          猜你喜欢
          • 2016-10-12
          • 1970-01-01
          • 2018-06-07
          • 1970-01-01
          • 2015-10-30
          • 1970-01-01
          • 1970-01-01
          • 2012-11-15
          • 2016-09-09
          相关资源
          最近更新 更多