Skip to content

Instantly share code, notes, and snippets.

@lilyball
Forked from antifuchs/exec_program.rs
Created September 15, 2013 04:43
Show Gist options
  • Select an option

  • Save lilyball/6568087 to your computer and use it in GitHub Desktop.

Select an option

Save lilyball/6568087 to your computer and use it in GitHub Desktop.
#[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 mut c_args = args.map(|arg| { arg.to_c_str().unwrap() });
c_args.push(ptr::null());
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