Xen / examples v0.1.0-demo.2
Read a pipeline
This topic is not available in the selected language or version. Showing the start of this section.
Read a pipeline
Run from the repository or distribution root. Put xen on PATH, or substitute ./bin/xen.
Without a pipeline the program waits for end of input.
printf 'one two\nthree\n' | xen run examples/stdin_words.xenExpected output
Section titled “Expected output”onetwothreeComplete source
Section titled “Complete source”// SPDX-License-Identifier: MIT OR Apache-2.0use std.io as io;use std.string as text;
fn main() { let contents = match io.read_stdin() { Result.Ok(value) => value, Result.Err(error) => { panic(io.describe_error(error)); }, }; let words = text.split_ascii_whitespace(contents); for index in 0..words.len() { println(words.get(index)); }}Build an executable
Section titled “Build an executable”xen build examples/stdin_words.xen -o appRun the generated executable on a compatible Linux machine.