2010年6月11日 星期五

資料流導向

標準輸入輸出:
1 是表示 stdout,
2 是表示 stderr
/dev/null 表示 null 裝置


附加:
>>

導出:
>



------------------- 範例 -------------------------
a.
有個 code 有會輸出 stdout 到 out 檔案, error 到 stderr
{{{
public class hello {
public static void main(String[] args) {
System.out.println("stoudout");
System.err.println("error");
}
}
}}}

將 stdout 輸到 dev/null 因此只印出 error
{{{
[Andy@t-ap188 testscript]$ java hello 1>/dev/null
error
}}}

若將 error 輸到/dev/null, 則印出 stdout
{{{
[Andy@t-ap188 testscript]$ java hello 2>/dev/null
stoudout
}}}



//////////////////////////////////////////////////////
資料流導向:
常常在 shell 碰到互動的介面, 可用導向符號(<, <<)減少工作
1. command < file , 將互動的內容寫在 file, 使用檔案方式去完成.
2. command << keyword
interaction
...
keyword

用字元方式導入 command, 定義 keyword, 並在內輸入互動的內容.


b. 範例:
I. 使用檔案導入符號(<)
{{{
[ui01] /home/dhc00/PHYLIP/phylip-3.69/test > ../exe/protdist < inputfile
}}}
inputfile
{{{
testfile
Y
}}}

I. 使用字元導入符號 (<<)
{{{
#!/bin/sh
../exe/protdist << word
testfile
Y
word

}}}



參考:
http://linux.vbird.org/linux_basic/0320bash/csh/no3-2.html

沒有留言:

張貼留言