diff options
author | John Letey <30328854+johnletey@users.noreply.github.com> | 2019-05-27 07:28:14 +0100 |
---|---|---|
committer | Matan Kushner <hello@matchai.me> | 2019-05-27 02:28:14 -0400 |
commit | 4cd98d862dfabc9747f5c2acc6ce5a92ed575489 (patch) | |
tree | 74e69494fbdb5b25eb3e30e1d6aababb4ba265c6 | |
parent | c2b0f3ac491ce9693a481fc7e3ff186ed0b6d303 (diff) |
fix: Check both stderr and stdout for Python version (#66)
* fix python version not showing for version < 3.4
* make review changes
-rw-r--r-- | src/modules/python.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/modules/python.rs b/src/modules/python.rs index fdab440e3..f19da3509 100644 --- a/src/modules/python.rs +++ b/src/modules/python.rs @@ -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, } } |