copied logic from node's cp.exec method to better support the exec option on windows