Skip to main content

deepseek_rust_cli/tools/
code_ops.rs

1use anyhow::Result;
2use tokio::process::Command;
3
4pub async fn run_python_code(code: &str) -> Result<String> {
5    let mut cmd = Command::new("python3");
6    cmd.arg("-c").arg(code);
7
8    let output = match cmd.output().await {
9        Ok(out) => out,
10        Err(_) => {
11            // Fallback to 'python'
12            Command::new("python").arg("-c").arg(code).output().await?
13        }
14    };
15
16    Ok(format!(
17        "{}{}",
18        String::from_utf8_lossy(&output.stdout),
19        String::from_utf8_lossy(&output.stderr)
20    ))
21}