【问题标题】:Behavior of stderr and stdout differsstderr 和 stdout 的行为不同
【发布时间】:2020-01-11 22:08:28
【问题描述】:

stdout 和 stderr 在运行 tcshksh 时给出不同的结果。 据我了解,ksh 中的行为是正确的,而在 tcsh 中却不是。 我的目标是了解coutcerr 之间的区别,所以我写了一个小c++ 程序:

    std::cout<<"this goes in standard output\n";
    std::cerr<<"This goes in error output\n";

并生成out作为它的可执行文件。

我制作了两个 shell 脚本,一个用于 ksh,另一个用于 tcsh,如下所示:

:~/CPP/TEST [124]$ cat test
#!/bin/tcsh

      out 2>>error.log

:~/CPP/TEST [125]$ cat test1
#!/usr/bin/ksh

out 2>>error.log

:~/CPP/TEST [129]$ ./test
This goes in error output            //WRONG
:~/CPP/TEST [130]$ cat error.log
this goes in standard output         //WRONG
:~/CPP/TEST [131]$ ./test1
this goes in standard output         //OK
:~/CPP/TEST [132]$ cat error.log
this goes in standard output
This goes in error output            //OK

stderrstdout 的行为在 shell 之间不应该是相同的吗?

【问题讨论】:

    标签: c++ stdout ksh stderr tcsh


    【解决方案1】:

    根据this tcsh manual page需要使用&gt;&gt;&amp;重定向错误输出(以及标准输出)

    该手册还指出

    shell 目前无法重定向诊断输出,除非 重定向标准输出,但(command &gt;&gt; output-file) &gt;&amp; error-file 通常是可接受的解决方法。

    总而言之,在tcsh 中确实没有办法将错误输出仅重定向到文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-23
      • 2011-08-02
      • 2011-10-30
      • 2019-08-21
      • 1970-01-01
      • 2019-03-24
      • 2012-06-17
      相关资源
      最近更新 更多