Fix checking of return code from command in wait_for