Ensure output of previous program is closed before running new one