From 4cd98d862dfabc9747f5c2acc6ce5a92ed575489 Mon Sep 17 00:00:00 2001 From: John Letey <30328854+johnletey@users.noreply.github.com> Date: Mon, 27 May 2019 07:28:14 +0100 Subject: [PATCH] fix: Check both stderr and stdout for Python version (#66) * fix python version not showing for version < 3.4 * make review changes --- src/modules/python.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/modules/python.rs b/src/modules/python.rs index fdab440e..f19da350 100644 --- a/src/modules/python.rs +++ b/src/modules/python.rs @@ -46,7 +46,18 @@ pub fn segment(context: &Context) -> Option { fn get_python_version() -> Option { 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, } }