winure/dos-var/src/main.rs

38 lines
752 B
Rust
Raw Normal View History

2024-07-12 14:05:01 -04:00
use std::{
env::args,
process::{
Command,
Stdio
}
};
mod error;
const CMD: &str = "/mnt/c/Windows/System32/cmd.exe";
pub fn main() {
let args: Vec<String> = args().collect();
if args.len() != 2 { error::arg_count(); }
let target = &args[1];
let cmd = Command::new(CMD)
.current_dir("/mnt/c/")
.arg( format!("/C echo %{target}%") )
.output();
if let Ok(output) = cmd {
if let Ok(stdout) = String::from_utf8(output.stdout) {
// trim output
let stdout = stdout.trim_end_matches("\"\r\n");
// catch empty variable case
if stdout == format!("%{target}%") { error::not_found(&target); }
// convert and write
let path = stdout
.replace("\\", "/")
.replace("C:/", "/mnt/c/");
println!("{path}");
}
}
}