Make collect_env more robust on Windows (#39136)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/39133.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/39136
Differential Revision: D21763686
Pulled By: zou3519
fbshipit-source-id: d45c3b529f569554e987dfd29579fc93d4894aaf