MCPcopy Index your code
hub / github.com/dgrunwald/rust-cpython / run_python_script

Function run_python_script

python3-sys/build.rs:180–196  ·  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

178
179/// Run a python script using the specified interpreter binary.
180fn 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"))]

Callers 2

get_macos_linkmodelFunction · 0.70

Calls 1

to_stringMethod · 0.80

Tested by

no test coverage detected