Created
September 15, 2013 04:41
-
-
Save antifuchs/6568076 to your computer and use it in GitHub Desktop.
This file contains 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
#[fixed_stack_segment] | |
fn exec_program(program: &str, args: &[~str]) { | |
do program.to_c_str().with_ref() |c_program| { | |
// I don't much care about the ownership of the strings here | |
// at this point, so let's just fail if execvp isn't working. | |
unsafe { | |
let c_args = args.map(|arg| { arg.to_c_str().unwrap() }); | |
// c_args needs a NULL attached to the end though. Here's what I tried: | |
// let c_args = args.map(|arg| { arg.to_c_str().unwrap() }) + [ptr::null()]; // this screams about unconstrained types. | |
execvp(c_program, vec::raw::to_ptr(c_args)); | |
// perror("Running tmux failed:".to_c_str().unwrap()); // Super horrific, apparently, let's use it for debugging only. | |
} | |
fail!(fmt!("Couldn't exec %s", program)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment