Run a python script using the specified interpreter binary.
(interpreter: &str, script: &str)
| 178 | |
| 179 | /// Run a python script using the specified interpreter binary. |
| 180 | fn run_python_script(interpreter: &str, script: &str) -> Result<String, String> { |
| 181 | let mut cmd = Command::new(interpreter); |
| 182 | cmd.arg("-c").arg(script); |
| 183 | |
| 184 | let out = cmd |
| 185 | .output() |
| 186 | .map_err(|e| format!("failed to run python interpreter `{:?}`: {}", cmd, e))?; |
| 187 | |
| 188 | if !out.status.success() { |
| 189 | let stderr = String::from_utf8(out.stderr).unwrap(); |
| 190 | let mut msg = "python script failed with stderr:\n\n".to_string(); |
| 191 | msg.push_str(&stderr); |
| 192 | return Err(msg); |
| 193 | } |
| 194 | |
| 195 | Ok(String::from_utf8(out.stdout).unwrap()) |
| 196 | } |
| 197 | |
| 198 | #[cfg(not(target_os = "macos"))] |
| 199 | #[cfg(not(target_os = "windows"))] |
no test coverage detected