Popup quickfix window only if the compiler finds an error

Hi, everyone.

Is someone aware of a way of taking the exit status of a compiler command (if it failed or not) and use it to determine whether the quickfix window should popup or not?

I have some idea of how I can use the exit status to make it, but I don’t know how I can manage to wait the compilation to finish for then take its exit status.

Thanks.