[plt-scheme] DrScheme becomes unstable after using (system ...) function, any suggestions?

From: Yavuz Arkun (yarkun at gmail.com)
Date: Sun Dec 23 11:40:34 EST 2007

While trying to use the system function from process.ss library, I 
discovered that DrScheme becomes unstable after calling this procedure 
several hundred times. Here is the bug report that I submitted (#9119):


In short, my program makes about 100 calls per run similar to:

(system "a-program.exe > test.txt")

and compares the test.txt to an expected output.

and after hitting "Run" button about 3 times, DrScheme terminates 
without any warning or error message. I am running 371.3 on Windows XP. 
The exe that is run via system doesn't seem to matter, neither does 
using Scheme/Limit Memory... option. MzScheme has no problem with the 
program when run outside DrScheme.

I need expert opinion on what I can do to solve this problem, short of 
ditching DrScheme. As a newbie Scheme user, I would very much like to 
use DrScheme to develop  instead of wrestling with Emacs or plain editors.

If you are curious about the program, I just began implementing a Scheme 
compiler and test suite following Abdulaziz Ghuloum's paper "An 
Incremental Approach to Compiler Construction" to teach myself Scheme. 
For each of the hundreds of tests, it compiles a small test program, 
runs it and compares its output to expected output.

Thanks for any help in advance,

For the record here are the things I have already tried:

I tried to use shell-execute:

(shell-execute "" "cmd.exe" "/C .\\a-program.exe > test.txt"
                (current-directory) 'sw_showminnoactive))

but it doesn't seem to work (probably because shell-execute is 
asynchronous and the file is not always updated when the comparison is 

I also tried to write a 'clean' version of the system function:

(define (system/clean cmd)
   (if (string? cmd)
       (let ((p (process cmd)))
         ((car (cddddr p)) 'wait)
         (display ((car (cddddr p)) 'status)) ; just for debugging
         (close-input-port (car p))
         (close-output-port (cadr p))
         (close-input-port (cadddr p))
       (error 'system/clean "not a string ---" cmd))))

and to call it with

   (system/clean "a-program.exe > test.txt")

but it still doesn't seem to finish writing the file by the time the 
comparison is done. I added 1-2sec waits, still no go. (Interestingly, 
the file seems to be written eventually after the program finishes 
because a consecutive run passes the first such comparison.)

Posted on the users mailing list.