標準入力からの読み込み(Python)
一行ごとに読み込み
#!/usr/bin/env/env python
# -*- coding: utf-8 -*-
import sys
if not sys.stdin.isatty():
for line in sys.stdin:
sys.stdout.write(line)
else:
print('No stdin.')
$ ls / | ./test1.py bin boot dev ... $ ./test1.py No stdin.
まとめて読み込み
#!/usr/bin/env/env python
# -*- coding: utf-8 -*-
import sys
if not sys.stdin.isatty():
lines = sys.stdin.read()
sys.stdout.write(lines)
else:
print('No stdin.')
$ ls / | ./test2.py bin boot dev ... $ ./test2.py No stdin.