Skip to content

Commit

Permalink
fix: Check both stderr and stdout for Python version (#66)
Browse files Browse the repository at this point in the history
* fix python version not showing for version < 3.4

* make review changes
  • Loading branch information
jletey authored and Matan Kushner committed May 27, 2019
1 parent c2b0f3a commit 4cd98d8
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/modules/python.rs
Expand Up @@ -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,
}
}
Expand Down

0 comments on commit 4cd98d8

Please sign in to comment.