pub fn run_pipeline(
    shell: &mut Shell, 
    job_id: i32,
    cmds: Vec<Cmd>,
    background: bool, 
    capture: bool) -> Result<(bool, CommandResult), ShellError> {
    
    //defaults to return
    let mut term_given = false;
    let mut cmdresult = CommandResult::new();

    //making vec of pipes
    let mut pipes = Vec::new();
    for _ in 0..cmds.len() - 1 {
        pipes.push(pipe()?);
    }

    let isatty = isatty(1)?;

    let mut pgid = Pid::from_raw(0);
    let mut idx: usize = 0;
    let mut children = Vec::new();

    for cmd in cmds {

        let params = CommandParams{
            isatty: isatty,
            background: background,
            capture_output: capture, //is used in command expansion only
            env: shell.env().clone(),
        };

        let childpid = run_command(
            job_id,
            cmd, 
            idx, 
            &mut pgid,
            &pipes,
            params,
            shell,
            &mut term_given,
            &mut cmdresult,
        )?;
        if childpid > 0 && !background {
            children.push(childpid);
        }
        idx += 1;
    }

    let mut status: i32 = 0;
    for childpid in children {
        status = jobc::wait_on_job(
            shell, 
            pgid, 
            Pid::from_raw(childpid), 
            true
        );
        cmdresult.status = status;
    }
    
    for pipe in pipes {
        close(pipe.0)?;
        match close(pipe.1) {
            Ok(_) => {},
            Err(_) => {}
        }
    }

    if background {
        if let Some(job) = shell.get_job_by_pgid(pgid) {
            eprintln!("[{}] {} {}", job.id, job.pgid, job.firstcmd);
        }
    }
    
    if status == STOPPED {
        jobc::mark_job_as_stopped(shell, job_id);
    }
    Ok((term_given, cmdresult))
}
/// Even lower level, it deconstructs the job
/// and passes raw parameters to the final function.
Even lower level, it deconstructs the job
and passes raw parameters to the final function.
Even lower level it deconstructs the job and passes raw parameters to the final function .
pub fn run_pipeline(
    shell: &mut Shell, 
    job_id: i32,
    cmds: Vec<Cmd>,
    background: bool, 
    capture: bool) -> Result<(bool, CommandResult), ShellError> {
    //defaults to return
    let mut term_given = false;
    let mut cmdresult = CommandResult::new();
    //making vec of pipes
    let mut pipes = Vec::new();
    for _ in 0..cmds.len() - 1 {
        pipes.push(pipe()?);
    }
    let isatty = isatty(1)?;
    let mut pgid = Pid::from_raw(0);
    let mut idx: usize = 0;
    let mut children = Vec::new();
    for cmd in cmds {
        let params = CommandParams{
            isatty: isatty,
            background: background,
            capture_output: capture, //is used in command expansion only
            env: shell.env().clone(),
        };
        let childpid = run_command(
            job_id,
            cmd, 
            idx, 
            &mut pgid,
            &pipes,
            params,
            shell,
            &mut term_given,
            &mut cmdresult,
        )?;
        if childpid > 0 && !background {
            children.push(childpid);
        }
        idx += 1;
    }
    let mut status: i32 = 0;
    for childpid in children {
        status = jobc::wait_on_job(
            shell, 
            pgid, 
            Pid::from_raw(childpid), 
            true
        );
        cmdresult.status = status;
    }
    for pipe in pipes {
        close(pipe.0)?;
        match close(pipe.1) {
            Ok(_) => {},
            Err(_) => {}
        }
    }
    if background {
        if let Some(job) = shell.get_job_by_pgid(pgid) {
            eprintln!("[{}] {} {}", job.id, job.pgid, job.firstcmd);
        }
    }
    if status == STOPPED {
        jobc::mark_job_as_stopped(shell, job_id);
    }
    Ok((term_given, cmdresult))
}
pub fn run_pipeline ( shell : & mut Shell , job_id : i32 , cmds : Vec < Cmd > , background : bool , capture : bool ) -> Result < ( bool , CommandResult ) , ShellError > { //defaults to return let mut term_given = false ; let mut cmdresult = CommandResult :: new ( ) ; //making vec of pipes let mut pipes = Vec :: new ( ) ; for _ in 0 .. cmds . len ( ) - 1 { pipes . push ( pipe ( ) ? ) ; } let isatty = isatty ( 1 ) ? ; let mut pgid = Pid :: from_raw ( 0 ) ; let mut idx : usize = 0 ; let mut children = Vec :: new ( ) ; for cmd in cmds { let params = CommandParams { isatty : isatty , background : background , capture_output : capture , //is used in command expansion only env : shell . env ( ) . clone ( ) , } ; let childpid = run_command ( job_id , cmd , idx , & mut pgid , & pipes , params , shell , & mut term_given , & mut cmdresult , ) ? ; if childpid > 0 && ! background { children . push ( childpid ) ; } idx += 1 ; } let mut status : i32 = 0 ; for childpid in children { status = jobc :: wait_on_job ( shell , pgid , Pid :: from_raw ( childpid ) , true ) ; cmdresult . status = status ; } for pipe in pipes { close ( pipe . 0 ) ? ; match close ( pipe . 1 ) { Ok ( _ ) => { } , Err ( _ ) => { } } } if background { if let Some ( job ) = shell . get_job_by_pgid ( pgid ) { eprintln ! ( " " job id job pgid job firstcmd ) ; } } if status == STOPPED { jobc :: mark_job_as_stopped ( shell , job_id ) ; } Ok ( ( term_given , cmdresult ) ) }
Even lower level, it deconstructs the job
and passes raw parameters to the final function.
Even lower level it deconstructs the job and passes raw parameters to the final function .
shell
&mut Shell
job_id
i32
cmds
Vec<Cmd>
background
bool
capture
bool