My goal is to have my cli program accept a stream of files
eg. Directory example_data has the following files
a.txtb.txtc.txt
I would like my rust program to handle something like the following
cargo run < example_data/*.txt
Is this type of setup possible? What's an alternative to this? I don't want to have to pass the file names individually to the program. Any suggestions?
cargo run <a.txtwill redirect the file contents into the program's stdin, but only one file, it doesn't work for globs (i.e.*s for multiple files). You can docargo run *.txtwhich will send multiple arguments to the process. You can access those in Rust viastd::env::args.std::io::stdin()catis for. That is,whatever < example_data/*.txtdoes not work, because the wildcard is not expanded in that position, but incat example_data/*.txt | whateverthe wildcard gets expanded andcatcombines the files in one stream that is passes to the standard input of whatever. Whatever might becargo run, that is rather incidental.