パイプで標準入力から受け取ったものを処理(stdin,pipe)
Python
py
for line in sys.stdin: ...
py
import sys
for line in sys.stdin:
print '##' + line.rstrip()
Bash
bash
cat - | <次のコマンド>
- 関数内で、標準入力を受け取る には
cat -
などと書く
bash
function aaa() {
echo "==== start ===="
cat - | grep "xxx"
echo "==== end ===="
}
find xxx -type f | func01
Ruby
rb
while (line = gets) do ... end
明示的に書くなら line = STDIN.gets
rb
io.popen("command", mode)
io.open("|command", mode)