shell_directive: fix race condition when running commands
Even though some commands exited with non-zero exit code, we sometimes
believed it exited with zero code due to a race condition. This patch
fixes that and also moves the code to a separate function
`os_utils.popen_rt()`.
Differential Revision: https://phab.qadevel.cloud.fedoraproject.org/D983