Make command execution more robust on windows (#6969)