Fix improper handling of pipe closing on Windows