1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use std::fs::File;
use std::io::Write;
use std::process::Command;
use std::str::from_utf8;
pub fn oce(command: &String) {
let filename = "result";
let command = command.split_whitespace().collect::<Vec<&str>>();
let command = if command[0] == "oce" {
&command[1..]
} else {
&command[0..]
};
let command_name = command.join(" ");
let shell_command = command[0];
let args = &command[1..];
let output = Command::new(shell_command)
.args(args)
.output()
.expect("Couldn't execute the command.");
let result =
from_utf8(&output.stdout).expect("Couldn't make a string from the command's result.");
let mut output_file = File::create(filename).expect("Failed to create a file.");
write!(output_file, "$ {}\n{}", command_name, result.trim())
.expect("Couldn't output anything.");
}