stdin
The stdin package reads standard input, which lets a Kiwi script work as a filter in a shell pipeline:
cat access.log | kiwi count-errors.kiwierrors = stdin::read().rtrim().lines().filter(do (l) => l.contains("ERROR"))println "${errors.size()} errors"| Function | Returns |
|---|---|
read() | Everything remaining on stdin, as a string. |
readline() | The next line, without its newline; "" at the end of input. |
readbytes() | Everything remaining, as bytes. |
empty() | Whether the input has been fully read. |
To process input line by line as it arrives, loop on readline until empty():
while !stdin::empty() do line = stdin::readline() println line.uppercase()endTo prompt the user interactively, use input or console::read.
Functions
Section titled “Functions”stdin::read
Section titled “stdin::read”stdin::read(): stringReads all of standard input as a string.
Returns string — The full stdin contents.
stdin::readbytes
Section titled “stdin::readbytes”stdin::readbytes(): bytesReads all of standard input as a byte array.
Returns bytes — The full stdin contents as bytes.
stdin::readline
Section titled “stdin::readline”stdin::readline(): stringReads a single line from standard input.
Returns string — The next line from stdin, without a trailing newline.
stdin::lines
Section titled “stdin::lines”stdin::lines(): listReads all lines from standard input into a list.
Returns list — A list of strings, one per line.
stdin::empty
Section titled “stdin::empty”stdin::empty(): booleanReturns true if standard input has no data available.
Returns boolean — true if stdin is empty, false otherwise.