Created
September 12, 2022 10:30
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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