|
|
@@ -108,8 +108,8 @@ impl<R: BufRead, W: Write> Shell<R, W> {
|
|
108
|
108
|
pub fn prompt(&mut self) -> Result<Option<String>, ErrorType> {
|
|
109
|
109
|
match env::current_dir() {
|
|
110
|
110
|
Ok(pwd) => {
|
|
111
|
|
- let _ = self.writer.write(
|
|
112
|
|
- format!("{} {} > ", self.name, pwd.display())
|
|
|
111
|
+ let _ = self.writer.write_all(
|
|
|
112
|
+ format!("{} {}> ", self.name, pwd.display())
|
|
113
|
113
|
.as_bytes(),
|
|
114
|
114
|
);
|
|
115
|
115
|
let _ = self.writer.flush();
|
|
|
@@ -126,7 +126,6 @@ impl<R: BufRead, W: Write> Shell<R, W> {
|
|
126
|
126
|
}
|
|
127
|
127
|
|
|
128
|
128
|
/// Runs a command.
|
|
129
|
|
- /// Currently only `cd` and `exit` are working.
|
|
130
|
129
|
fn run(&mut self, command: Command) -> Result<(), ErrorType> {
|
|
131
|
130
|
|
|
132
|
131
|
match command {
|
|
|
@@ -185,11 +184,18 @@ impl<R: BufRead, W: Write> Shell<R, W> {
|
|
185
|
184
|
Ok(())
|
|
186
|
185
|
}
|
|
187
|
186
|
|
|
188
|
|
- fn execute(&self, cmd: &str) {
|
|
|
187
|
+ fn execute(&mut self, cmd: &str) {
|
|
189
|
188
|
let parts: Vec<&str> = cmd.split_whitespace().collect();
|
|
190
|
189
|
let args: Vec<CString> = parts.iter().map(|f| CString::new(*f).unwrap()).collect();
|
|
|
190
|
+ let cmd = args.clone();
|
|
191
|
191
|
let t = args.into_boxed_slice();
|
|
192
|
192
|
|
|
193
|
|
- execvp(&t[0], &t).unwrap();
|
|
|
193
|
+ match execvp(&t[0], &t) {
|
|
|
194
|
+ Ok(_) => {},
|
|
|
195
|
+ Err(_) => {
|
|
|
196
|
+ let _ = self.writer.write_all(
|
|
|
197
|
+ format!("{:?}: command not found\n", cmd[0]).as_bytes());
|
|
|
198
|
+ },
|
|
|
199
|
+ }
|
|
194
|
200
|
}
|
|
195
|
201
|
}
|