On bash
#!/bin/bash

g++ -o gen generator.cpp

while true; do
        ./gen > bst.in
        ./bst_ok
        cp bst.out bst.ans
        ./bst_wrong
        if diff bst.ans bst.out; then
                exit
        fi
done
On cmd

g++ -o gen.exe generator.cpp

:start
gen.exe > bst.in
bst_ok.exe
copy bst.out bst.ans
bst_wrong.exe
fc bst.ans bst.out
if errorlevel 1 goto fail
goto start
:fail