Return result of subprocess + ensure file is closed