Process Structs
Process management และ child process handling
Command Builder
Section titled “Command Builder”use std::process::Command;
fn main() { // Basic command execution let output = Command::new("echo") .arg("Hello, World!") .output() .expect("Failed to execute command");
println!("Status: {}", output.status); println!("Stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("Stderr: {}", String::from_utf8_lossy(&output.stderr));
// Multiple arguments let output = Command::new("ls") .args(["-l", "-a"]) .output() .expect("Failed");
println!("\n=== ls -la ==="); println!("{}", String::from_utf8_lossy(&output.stdout));
// With environment variable let output = Command::new("sh") .arg("-c") .arg("echo $MY_VAR") .env("MY_VAR", "custom_value") .output() .expect("Failed");
println!("With env var: {}", String::from_utf8_lossy(&output.stdout));
// Current directory let output = Command::new("pwd") .current_dir("/tmp") .output() .expect("Failed");
println!("In /tmp: {}", String::from_utf8_lossy(&output.stdout));}เข้าสู่ระบบเพื่อดูเนื้อหาเต็ม
ยืนยันตัวตนด้วยบัญชี Google เพื่อปลดล็อกบทความทั้งหมด
Login with Google