This patch fixes the quoting for executing scripts on windows and splits the platform dependent code. Fixes #1875