ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/salaryman/trunk/src/main.rs
Revision: 2
Committed: Thu May 29 06:17:28 2025 UTC (4 months, 1 week ago) by yuzu
File size: 632 byte(s)
Log Message:
proof of concept: works

File Contents

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