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]
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.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.