make rawSystemIOWithEnv close its handles

(cherry picked from commit f6dae3813effa7cf1855b793a87a2b0efddf2f7e)