testsuite: A more portable solution to #9399
Previously we used an awful hybrid batch script/Bourne shell script to allow this test to run both on Windows and Linux (fixing #9399 (closed)). However, this breaks on some libc implementations (e.g. musl). Fix this.
Fixes #16798 (closed).