about summary refs log tree commit diff stats
path: root/src/main.rs
blob: 5538077e19acaddd4a86b63ad3c1f0edb262e379 (plain) (blame)
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
use serde::{Deserialize, Serialize};
use surrealdb::{RecordId, Surreal, engine::local::RocksDb};

use std::io::Read;
use std::process::{Child, Command, Stdio};

fn exec(image: &str, args: Vec<&str>) -> Result<Child, Box<dyn std::error::Error>> {
    let child = Command::new(image)
        .args(args)
        .stdin(Stdio::piped())
        .stdout(Stdio::piped())
        .spawn()?;
    Ok(child)
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut child = exec("java", vec!["-jar", "minecraft_server.jar"])?;
    std::thread::sleep(std::time::Duration::from_secs(60));
    let mut buf: [u8; 512] = [0; 512];
    child.stdout.as_mut().unwrap().read(&mut buf[..])?;
    println!("{}", String::from_utf8_lossy(&buf));
    child.kill()?;
    Ok(())
}