windjammer_runtime/platform/native/
process.rs1pub use crate::process::*;
7
8#[derive(Debug, Clone)]
10pub struct CommandOutput {
11 pub stdout: String,
12 pub stderr: String,
13 pub status: i32,
14}
15
16pub fn execute(command: String, args: Vec<String>) -> Result<CommandOutput, String> {
18 use std::process::Command;
19
20 let output = Command::new(&command)
21 .args(&args)
22 .output()
23 .map_err(|e| format!("Failed to execute command: {}", e))?;
24
25 let stdout = String::from_utf8_lossy(&output.stdout).to_string();
26 let stderr = String::from_utf8_lossy(&output.stderr).to_string();
27 let status = output.status.code().unwrap_or(-1);
28
29 Ok(CommandOutput {
30 stdout,
31 stderr,
32 status,
33 })
34}
35
36pub fn spawn(command: String, args: Vec<String>) -> Result<ProcessHandle, String> {
37 use std::process::Command;
38
39 let child = Command::new(&command)
40 .args(&args)
41 .spawn()
42 .map_err(|e| format!("Failed to spawn command: {}", e))?;
43
44 Ok(ProcessHandle {
45 id: child.id() as i32,
46 })
47}
48
49#[derive(Debug, Clone)]
50pub struct ProcessHandle {
51 pub id: i32,
52}