Skip to content

Instantly share code, notes, and snippets.

@hayajo
Last active January 1, 2017 07:53
Show Gist options
  • Save hayajo/ebc7d72851dede572021c40f2cbfdcca to your computer and use it in GitHub Desktop.
Save hayajo/ebc7d72851dede572021c40f2cbfdcca to your computer and use it in GitHub Desktop.
Rustでコマンド実行
use std::process::Command;
fn prepare_cmd(cmd: &str, args: &[&str]) -> Command {
let mut cmd = Command::new(cmd);
for arg in args {
cmd.arg(arg);
}
cmd
}
fn main() {
let args = vec!["ls", "-l", "-a", "-h"];
let mut cmd = prepare_cmd(args[0], &args[1..]);
cmd.spawn().expect("command failed to start");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment