Last active
January 3, 2016 01:49
-
-
Save quux00/8391823 to your computer and use it in GitHub Desktop.
Mutable pointers in Rust
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::run; | |
use std::str; | |
fn main() { | |
let options = run::ProcessOptions::new(); | |
let process = run::Process::new("fuser", &[~"-m", ~"/media/truecrypt3"], options); | |
match process { | |
Some(mut p) => { | |
let outdata = p.finish_with_output(); | |
let outtxt = str::from_utf8(outdata.output); | |
if outtxt == "" { | |
println("WARN: No process was found holding /media/truecrypt3 mount"); | |
} else { | |
kill_proc(outtxt.trim()); | |
} | |
}, | |
None => println("WARN: Unable to run fuser command (null output)") | |
} | |
} | |
fn kill_proc(process_id: &str) { | |
let trimmed = process_id.into_owned(); | |
let options = run::ProcessOptions::new(); | |
let process = run::Process::new("kill", &[trimmed], options); | |
match process { | |
Some(_) => println("Done"), | |
None => println("Kill failed") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment