ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/salaryman/trunk/src/main.rs
Revision: 4
Committed: Sat May 31 16:34:45 2025 UTC (4 months, 1 week ago) by yuzu
File size: 787 byte(s)
Log Message:
add new dependencies

File Contents

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