Skip to content

Instantly share code, notes, and snippets.

@taybenlor
Created September 12, 2022 10:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taybenlor/df261f5958ce9be694b15f6fb7ce44f6 to your computer and use it in GitHub Desktop.
Save taybenlor/df261f5958ce9be694b15f6fb7ce44f6 to your computer and use it in GitHub Desktop.
This program writes whatever you type into STDIN to the file specified in arg1.
use std::io::Read;
use std::{env, fs, io};
fn main() {
let filename = env::args().nth(1).expect("no filename provided");
let stdin = io::stdin();
let mut buf = String::new();
stdin
.lock()
.read_to_string(&mut buf)
.expect("unable to read from STDIN");
fs::write(&filename, &buf).expect("unable to create file");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment