Ref T13209. This gives us a clean suite under Windows. The actual changes are a lot of miscellaneous stuff which I'll walk through inline in more detail.
The biggest change here is just rewriting some stuff like cat, echo, sleep, etc., in PHP. These commands either don't exist, don't work the same way, or are shell builtins (and we're now bypassing the shell) under Windows. So replace cat ... with php -f cat.php -- ... to make the tests portable.