Skip to content

add a macro rule system! #12915

Closed
Closed
@electricface

Description

macro_rules! system(
    ( $cmd:expr ) => (
        {
            let config = ::std::io::ProcessConfig {
                program: $cmd,
                args: &[],
                stdin: ::std::io::process::InheritFd(0),
                stdout: ::std::io::process::InheritFd(1),
                stderr: ::std::io::process::InheritFd(2),
                .. ::std::io::ProcessConfig::new()
            };

            let mut pro = match ::std::io::Process::configure(config){
                Ok(o) => o,
                Err(e) => fail!("failed to execute process: {} [{}]", $cmd ,e)
            };
            pro.wait()
        }
    );

    ( $cmd:expr,$($args:expr)* ) => (
        {
            let config = ::std::io::ProcessConfig {
                program: $cmd,
                args: &[$($args)*],
                stdin: ::std::io::process::InheritFd(0),
                stdout: ::std::io::process::InheritFd(1),
                stderr: ::std::io::process::InheritFd(2),
                .. ::std::io::ProcessConfig::new()
            };

            let mut pro = match ::std::io::Process::configure(config){
                Ok(o) => o,
                Err(e) => fail!("failed to execute process: {} [{}]", $cmd ,e)
            };
            pro.wait()
        }
    )
)

like the perl 's "system" function.

fn main(){
    let ret = system!("bc",);
    println!("{}" , ret );
}

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions