Last active
January 1, 2017 07:53
-
-
Save hayajo/ebc7d72851dede572021c40f2cbfdcca to your computer and use it in GitHub Desktop.
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::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