ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/salaryman/trunk/src/main.rs
Revision: 3
Committed: Thu May 29 06:24:25 2025 UTC (4 months, 1 week ago) by yuzu
File size: 668 byte(s)
Log Message:
cargo fmt

File Contents

# Content
1 use std::io::Read;
2 use std::process::{Child, Command, Stdio};
3
4 fn exec(image: &str, args: Vec<&str>) -> Result<Child, Box<dyn std::error::Error>> {
5 let child = Command::new(image)
6 .args(args)
7 .stdin(Stdio::piped())
8 .stdout(Stdio::piped())
9 .spawn()?;
10 Ok(child)
11 }
12
13 fn main() -> Result<(), Box<dyn std::error::Error>> {
14 let mut child = exec("java", vec!["-jar", "minecraft_server.jar"])?;
15 std::thread::sleep(std::time::Duration::from_secs(60));
16 let mut buf: [u8; 512] = [0; 512];
17 child.stdout.as_mut().unwrap().read(&mut buf[..])?;
18 println!("{}", String::from_utf8_lossy(&buf));
19 child.kill()?;
20 Ok(())
21 }