0

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]
1
  • 2
    Compiler error messages get printed to standard error, not standard output. Commented Jan 13, 2014 at 8:51

1 Answer 1

4

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.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.