I have the following Python code in which I'm calling a Makefile by embedding the bash command from within the python script. I want to check if a warning is reported on the stdout. I do see the warning on the stdout but my Python code does not seem to be detecting it.
Python Code:
maker = subprocess.Popen(["bash", "-c", "make"], stdout=subprocess.PIPE)
for line in maker.stdout:
if "warning:" in line:
print "Warning(s) detected in make"
Output on stdout which clearly reports a warning:
main.c: In function ‘main’:
main.c:46:14: warning: unused variable ‘options’ [-Wunused-variable]
asked Jan 13, 2014 at 8:46
Zahaib Akhtar
1,0782 gold badges12 silver badges26 bronze badges
-
2Compiler error messages get printed to standard error, not standard output.Barmar– Barmar2014年01月13日 08:51:37 +00:00Commented Jan 13, 2014 at 8:51
1 Answer 1
Try catching stderr as well:
subprocess.Popen(["bash", "-c", "make"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(As user "Barmar" already noted, compiler error messages are sent to stderr.)
answered Jan 13, 2014 at 8:51
Michael Helwig
5304 silver badges12 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
default