use std::io; use std::io::Write; use std::process; use std::process::{Command, Stdio}; use std::env; fn run_process(iterp: &String, prog: &String, args: &Vec) { let prog = format!("{}", prog.to_owned()); //println!("{}", prog); let opt = if iterp == "ruby" { "-e" } else { "-c" }; let output = Command::new(iterp) .arg(opt) .arg(prog) .args(args) .stdin(Stdio::inherit()) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) .output() .expect("failed to execute process"); //println!("status: {}", output.status.code().unwrap()); std::process::exit(output.status.code().unwrap()); } fn main() { let prog = vec![115, 112, 97, 119, 110, 32, 115, 115, 104, 32, 107, 97, 110, 103, 64, 49, 57, 50, 46, 49, 54, 56, 46, 51, 46, 52, 10, 101, 120, 112, 101, 99, 116, 32, 34, 80, 97, 115, 115, 119, 111, 114, 100, 58, 34, 10, 115, 101, 110, 100, 32, 34, 120, 120, 92, 114, 34, 10, 101, 120, 112, 101, 99, 116, 32, 34, 37, 34, 10, 115, 101, 110, 100, 32, 34, 112, 115, 32, 45, 101, 102, 32, 124, 103, 114, 101, 112, 32, 110, 103, 105, 110, 120, 92, 114, 34, 10, 101, 120, 112, 101, 99, 116, 32, 34, 37, 34, 10, 115, 101, 110, 100, 32, 34, 101, 120, 105, 116, 92, 114, 34, 10, 10]; let pass = ""; let iterp = "expect"; if pass.len() != 0 { let mut input = String::new(); print!("Password: "); io::stdout().flush().ok(); io::stdin() .read_line(&mut input) .ok() .expect("Couldn't read password"); if input.trim() != pass { println!("Invalid password!"); process::exit(1); } } let prog_str = String::from_utf8(prog).unwrap(); //println!("running ...:\n {}", prog_str); let mut args = env::args().collect::>(); args.drain(0..1); run_process(&iterp.to_string(), &prog_str, &args); }