Rewrite test-launching logic
Fix empty temp file on Windows

Apparently, in Windows when the file is first opened in "w+", the
redirection in shell is lost. Opening the file afterwards solves this.

The temporary file name and the command is now created based on used
operating system.