fix: Check both stderr and stdout for Python version (#66)

* fix python version not showing for version < 3.4

* make review changes
This commit is contained in:
John Letey 2019-05-27 07:28:14 +01:00 committed by Matan Kushner
parent c2b0f3ac49
commit 4cd98d862d
1 changed files with 12 additions and 1 deletions

View File

@ -46,7 +46,18 @@ pub fn segment(context: &Context) -> Option<Module> {
fn get_python_version() -> Option<String> {
match Command::new("python").arg("--version").output() {
Ok(output) => Some(String::from_utf8(output.stdout).unwrap()),
Ok(output) => {
// We have to check both stdout and stderr since for Python versions
// < 3.4, Python reports to stderr and for Python version >= 3.5,
// Python reports to stdout
if output.stdout.is_empty() {
let stderr_string = String::from_utf8(output.stderr).unwrap();
Some(stderr_string)
} else {
let stdout_string = String::from_utf8(output.stdout).unwrap();
Some(stdout_string)
}
}
Err(_) => None,
}
}