Link to home
Start Free TrialLog in
Avatar of NMathisen

asked on

Read a text file and output to web as it's updated


I have an ASP application that executes a file on my server using ASPExec wich then directs the output to a text file.  The processing time it takes for this task to complete can be anywhere from 15 minutes to a lot longer depending on how many times it has to run the routine.  When the process is completed, the ASP script will then read the output.txt file and display it on the page.

My question is, how can I parse the output.txt file gradually so as data is sent to it I can display it on the page, almost live?  I'm trying to avoid the "waiting" state for 20 minutes and then showing it all at once.

Avatar of NMathisen


I've attached the current code I'm using to read the file.  And to clarify, the output to the file is not formatted as it is simply a console based application and I'm redirecting all console output to the file.
If done then ' Done running utility, display results
	  Dim ReadString
	   Set FileStreamObject = CreateObject("Scripting.FileSystemObject")
	   Set ReadStream = FileStreamObject.OpenTextFile (Server.MapPath ("output.txt"), 1)
	   If ReadStream.AtEndOfStream <> TRUE Then
	    ReadString = ReadStream.ReadAll
	    Response.Write ("<div>Your decoding request has been completed, please view the results below." )
		Response.Write "Result: <pre>" & sResult & "</pre>"
	    Response.write "<hr><center><pre>" & ReadString & "</pre></center><hr></div>"
	    End If
	    Set ReadStream = Nothing

Open in new window

Avatar of mikelfritz
What Operating system?

Can the "ASP script" - at least the bit about displaying the page - be run independently of the application that is writing to the output text file?

It's running on Windows 2K3 Server, and the script basically calls a batch file which runs an executable with some arguments sent to an "input" file from the first half of the ASP page.  So after the user enters the info, it's written to input.txt and the script then executes the batch file and throws the output to output.txt.
Avatar of mikelfritz
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I will give that a try to see how it goes.  Also, I've noticed that it if I watch the command prompt when not redirecting the output, there is a lot of output on the screen almost immediately.  Why, when redirecting the output does it take upwards of 10 minutes before the text file has any information written to it?  Is this a buffer thing with the Windows command prompt?  
how about a redirect at the command prompt when not redirecting from within the script?

script.bat > output.txt
Could you explain more?  I have the current batch file who's entire output is not redirected, just the important command.

Inside batch file there are other commands, then there's this one:
Ex:  myexe.exe -input.txt > output.txt

Would it be better to simply call the entire batch file while redirecting the output?
You are essentially doing what I said already inside the batch file.  So you are saying that if you run:
myexe.exe -input.txt
It displays stuff right away
And if you run:
myexe.exe -input.txt > output.txt
It takes a while for anything to get into output.txt  ?
That is correct, that's why I think it has something to do with a buffer or something.  When the output finally does start to show up, it does so in big chunks.
Not exactly the fix I was looking for, but it will do.