io
readLine()— the next line of stdin without\nor\r\n, ornilat the end.readText()— the rest of stdin.write(v)— writesvto stdout asprintdoes, without a newline.eprint(v),ewrite(v)— the same to stderr, with and without a newline.
Reading stdin or writing stderr first flushes what was printed.
A filter that sums the numbers it is given, one per line, and warns about the lines that are not numbers:
// sum.rn
let mut total = 0;
let mut line = io.readLine();
while line != nil {
try {
total += number(line);
} catch e is ValueError {
io.eprint("skipping '{line}'");
}
line = io.readLine();
}
io.write("total: ");
print(total);
$ printf '10\n20\nabc\n12\n' | rune run sum.rn
skipping 'abc'
total: 42
readText() takes all of stdin at once, for input that is not line by line:
// count.rn
let words = regex.split(r"\s+", io.readText().trim());
print("{words.len()} words");
$ echo "the quick brown fox" | rune run count.rn
4 words