Does this script work if you run it from Script Editor?
Share and Enjoy
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"
Why are you doing that to being with? Don't try to use AppleScript to interact with the Terminal from an app. That is simply never, ever going to work for multiple reasons. Just get the data directly and display it within your app.
I think your problem is the test on "count of windows". If the only window open is your Terminal window with name of "Test Log," the test still succeeds and you don't close the window. You might want to test against 0.