close file before executing cmd