Add tryCatch for closing stdin