This repository was archived by the owner on Mar 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcpp.rs
More file actions
58 lines (56 loc) · 1.71 KB
/
cpp.rs
File metadata and controls
58 lines (56 loc) · 1.71 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use std::{
fs::File,
process::{Child, Command, Stdio},
};
use crate::error::SimulatorError;
pub struct Runner {
current_dir: String
}
impl Runner {
pub fn new(current_dir: String) -> Self {
Runner {
current_dir
}
}
pub fn run(&self, stdin: File, stdout: File) -> Result<Child, SimulatorError> {
let compile = Command::new("make")
.args(["all"])
.current_dir(&self.current_dir.to_owned())
.stdout(Stdio::null())
.stderr(Stdio::piped())
.spawn()
.map_err(|err| {
SimulatorError::UnidentifiedError(format!(
"Couldnt spawn compilation command: {}",
err
))
})?;
let compile_output = compile.wait_with_output().map_err(|err| {
SimulatorError::UnidentifiedError(format!(
"Waiting on compilation process failed: {}",
err
))
})?;
if !compile_output.status.success() {
return Err(SimulatorError::CompilationError(
String::from_utf8(compile_output.stderr)
.unwrap()
.trim()
.to_owned(),
));
}
Command::new("timeout".to_owned())
.args(["3", "./run"])
.current_dir(&self.current_dir.to_owned())
.stdin(stdin)
.stdout(stdout)
.stderr(Stdio::piped())
.spawn()
.map_err(|err| {
SimulatorError::UnidentifiedError(format!(
"Couldnt spawn the C++ runner process: {}",
err
))
})
}
}