Skip to content

Commit

Permalink
simple piping (without redirections) is working.. Still needs error h…
Browse files Browse the repository at this point in the history
…andling and testing
  • Loading branch information
bexxmodd committed Jul 17, 2021
1 parent e9eac8a commit 944a3ce
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use signal_hook::{
consts::{SIGINT, SIGQUIT},
iterator,
};
use std::fs::{File, OpenOptions};
use std::{fs::{File, OpenOptions}, io::Read};
use std::{
error::Error,
io::{self, Write},
Expand Down Expand Up @@ -49,7 +49,24 @@ fn execute_shell() {

let mut cmd_line = get_user_commands();

if cmd_line.has_redirection() {
if cmd_line.is_pipe() {
let mut before_pipe_cmd = cmd_line.commands_before_pipe();
let cmd = before_pipe_cmd.get_args();
let cmd2 = cmd_line.get_args();
let mut proc2 = process::Command::new(&cmd2[0])
.args(&cmd2[1..])
.stdin(process::Stdio::piped())
.spawn()
.unwrap();

let mut proc1 = process::Command::new(&cmd[0])
.args(&cmd[1..])
.stdout(proc2.stdin.unwrap())
.output()
.unwrap();
}

else if cmd_line.has_redirection() {
let cmd = cmd_line.peek().clone();
let mut proc = match redirect_cmd_execution(&mut cmd_line) {
Ok(p) => p,
Expand Down
12 changes: 12 additions & 0 deletions src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ impl Tokenizer {
args
}

pub fn commands_before_pipe(&mut self) -> Tokenizer {
let mut before = String::new();
while let Some(a) = self.next() {
if a.eq("|") {
break;
}
before.push_str(&a);
before.push_str(" ");
}
Tokenizer::new(&before)
}

pub fn get_args(&mut self) -> Vec<String> {
let mut args = vec![];
while let Some(a) = self.next() {
Expand Down

0 comments on commit 944a3ce

Please sign in to comment.