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

# Content
1 use serde::{Deserialize, Serialize};
2 use surrealdb::{RecordId, Surreal, engine::local::RocksDb};
3
4 use std::io::Read;
5 use std::process::{Child, Command, Stdio};
6
7 fn exec(image: &str, args: Vec<&str>) -> Result<Child, Box<dyn std::error::Error>> {
8 let child = Command::new(image)
9 .args(args)
10 .stdin(Stdio::piped())
11 .stdout(Stdio::piped())
12 .spawn()?;
13 Ok(child)
14 }
15
16 #[tokio::main]
17 async fn main() -> Result<(), Box<dyn std::error::Error>> {
18 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 }