MCPcopy Create free account
hub / github.com/dgrunwald/rust-cpython / run_python_script

Function run_python_script

python27-sys/build.rs:183–199  ·  view source on GitHub ↗

Run a python script using the specified interpreter binary.

(interpreter: &str, script: &str)

Source from the content-addressed store, hash-verified

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

Callers 2

get_macos_linkmodelFunction · 0.70

Calls 1

to_stringMethod · 0.80

Tested by

no test coverage detected