Reading from piped output if the input file not provided


What is a preferred way do implement a situation when the input file is not provided and it is assumed the input will be read from a piped output. A more concrete scenario :slight_smile:

// if input not provided
cat file.txt | ./myRustProgram

//if input provided
./myRustProgram -i file.txt

What I am trying to do is implement a reader that can automatically handle a situation whee if a file is not specified it automatically starts reading from stdin:

fn read (file: &str){               my cli sets the file to "stdin" if -i file.txt  is not provided
       let reader = match file {
            "stdin" => // What goes here?,
            _        =>  FileBuffer::open(file).unwrap()
        for line in reader.lines() {

Thank you !!

I've posted something similar recently:

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.