Close terminal window after app runs

I am trying to run a fortran program in the Terminal window, and when it is finished I want the Terminal window to close. The program has to run through the Terminal window so I can interact with it. I’ve tried to trick applescript… First I create a file, then when the fortran program finishes, it deletes the program. When the file is gone, applescript moves on to the next step and closes the window. The script is below. The problem is that the Finder only knows that the file has been deleted if I manually click on the folder to “update” the directory. Any suggestions?

Here is what I tried:


do shell script "ls " & infolder & " > " & local_path_unix & "files.dat"
tell application "Terminal"
	activate
	do script with command "cd " & local_path_unix & " ; ./a.out ; exit"
	
	set filesfile to local_path_mac & "files.dat"
	tell application "Finder"
		repeat while (exists file filesfile)
			delay 5
		end repeat
	end tell
	close window 1
end tell

does this part of a script help?

tell application "Terminal" to close window 1

Tom

Browser: iCab/4.1.1
Operating System: Mac OS X (10.4)