各言語での標準入力処理方法
2009年4月10日
1. bash
while read line
do
echo 'input='$line
done
2. py
while True:
line = raw_input()
print "input=" + line
3. rb
while (line = gets) do
puts 'input=' + line
end
4. php
<?php
while (true) {
$line = fgets(STDIN, 4096);
echo "input=" . $line;
}
?>
bashのreadや、
pythonのsys.stdin.read() や、
phpのfile_get_contents(‘php://stdin’);
・・・に相当するような、Rubyの「一回で標準入力全てを取得する」メソッドが発見できなかった。
rubyだとSTDIN.readでした。
pythonのsys.stdin.read() や、
phpのfile_get_contents(‘php://stdin’);
rubyだとSTDIN.readでした。