[code小心得]關於stdout

大家好  小弟又來嘴砲了

之前看到descenthttp://descent-incoming.blogspot.tw/2013/05/shell-stdoutstderr-redirect.html

shell stdout/stderr redirect



好文章  讓小弟想起也該紀錄一下。


基於上面提到的文章   大家應該都知道shell 有stdout的這種能力  ,bash   sh都有支援,ash可能沒有不是很確定。

那們不知各位大大是否有看過下面類似的寫法


      FILE *stream ;
      
      if((stream = freopen("file.txt", "w", stdout)) == NULL)
                 exit(-1);
             printf("Hello world");

      stream = freopen("CON", "w", stdout);

執行上面這段code,將不會看到Hello world,但是在file.txt 卻會看到Hello world,

在一般PC LINUX或是Embedded  linux上都應該支援,除非您的shell環境比較特別。

在這個網址 有比較詳細的講解
http://support.microsoft.com/kb/58667/zh-tw

這種寫法  對於需要儲存打印訊息是很方便,不過也建議不要濫用,不然似乎很容易亂掉和出事。
以上   如有錯誤歡迎指正   謝謝觀看

小弟下台一鞠躬

留言