| Crates.io | unistore-process |
| lib.rs | unistore-process |
| version | 0.1.1 |
| created_at | 2026-01-20 01:45:10.023888+00 |
| updated_at | 2026-01-20 07:11:31.051401+00 |
| description | Process management capability for UniStore |
| homepage | https://github.com/yangbo1317/unistore |
| repository | https://github.com/yangbo1317/unistore |
| max_upload_size | |
| id | 2055639 |
| size | 42,067 |
UniStore 进程管理能力,提供异步子进程创建和管理功能。
unistore-process 提供:
[dependencies]
unistore-process = "0.1"
use unistore_process::{Command, shell};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// 简单命令执行
let output = Command::new("echo")
.arg("Hello, World!")
.output()
.await?;
println!("stdout: {}", output.stdout_lossy());
// 使用 shell 执行
let output = shell("echo Hello from shell").await?;
println!("stdout: {}", output.stdout_lossy());
Ok(())
}
let output = Command::new("cargo")
.args(["build", "--release"])
.current_dir("/path/to/project")
.env("RUST_LOG", "debug")
.output()
.await?;
if output.success() {
println!("构建成功!");
} else {
eprintln!("构建失败: {}", output.stderr_lossy());
}
use std::time::Duration;
// 启动后台进程
let mut child = Command::new("my-server")
.spawn()
.await?;
println!("进程 ID: {}", child.id());
// 等待完成或超时
match child.wait_timeout(Duration::from_secs(30)).await? {
Some(status) => println!("进程退出: {:?}", status),
None => {
println!("超时,终止进程");
child.terminate().await?;
}
}
use unistore_process::{shell, exec, which};
// 执行 shell 命令
let output = shell("ls -la").await?;
// 执行命令并获取标准输出
let version = exec("rustc", &["--version"]).await?;
// 检查命令是否存在
if let Some(path) = which("cargo").await {
println!("cargo 位于: {}", path.display());
}
// 优雅终止(发送 SIGTERM / TerminateProcess)
child.terminate().await?;
// 强制终止(发送 SIGKILL / TerminateProcess)
child.kill().await?;
| 平台 | 支持状态 |
|---|---|
| Windows | ✅ |
| Linux | ✅ |
| macOS | ✅ |
MIT OR Apache-2.0
本 crate 基于以下优秀项目构建:
感谢 Tokio 团队提供的出色异步基础设施!