#shell #server #i64 #这是一个rust编写的unix域套接字服务器,用于从远端接收命令并执行。它支持命令执行、输出重定向,并提供了一个多线程环境来处理客户端请求。

shell_server

这是一个Rust编写的Unix域套接字服务器,用于从远端接收命令并执行。它支持命令执行、输出重定向,并提供了一个多线程环境来处理客户端请求。

2 releases

0.1.1 Jul 7, 2024
0.1.0 Jul 7, 2024

#477 in Unix APIs

Download history 176/week @ 2024-07-06 12/week @ 2024-07-13 22/week @ 2024-09-14 12/week @ 2024-09-21 36/week @ 2024-09-28 2/week @ 2024-10-05 1/week @ 2024-10-12

52 downloads per month

MIT license

14KB
237 lines

Rust shell Server端

示例

use libc::exit;
use shell_server::{reg_shell_cmd, Server, Shell};
fn print_hello() {
    println!("Hello, world!");
}
fn add_two(a: i64, b: i64) -> i64 {
    println!("{} + {} = {}", a, b, a + b);
    return a + b;
}
fn print_str(s: &String) {
    println!("{}", s);
}
fn add_seven(a: i64, b: i64, c: i64, d: i64, e: i64, f: i64, g: i64) -> i64 {
    println!(
        "{} + {} + {} + {} + {} + {} + {} = {}",
        a,
        b,
        c,
        d,
        e,
        f,
        g,
        a + b + c + d + e + f + g
    );
    return a + b + c + d + e + f + g;
}
fn get_self_pid() -> u64 {
    return std::process::id() as u64;
}
fn main() {
    let mut shell = Shell::new();
    reg_shell_cmd!(shell,
        {"hello", print_hello},
        {"add_two", add_two},
        {"print_str", print_str},
        {"add_seven", add_seven},
        {"run_exit", exit}
    );
    let pid = get_self_pid();
    println!("pid: {}", pid);
    match Server::new(
        shell,
        format!("/tmp/rust_shell_cmd_{}", pid),
        format!("/tmp/rust_shell_output_{}", pid),
    )
    .run()
    {
        Ok(_) => (),
        Err(err) => println!("run err: {}", err),
    }
}

Dependencies

~50KB