A suggestion: Maybe the best way to test this code, is to extract the body of the with-block starting at line 62 into a function, and test that with a bunch of external programs, which can then either exit with a good/bad status-code, or signal themselve or allocate too much memory?