Fix cmd.script on Windows.

Fixes #2972

Was previously creating a temp file on Windows, which couldn't be executed.
Just cache the file and run it when on Windows.