News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

SDK question

Started by Merrick, April 14, 2007, 10:38:51 PM

Previous topic - Next topic

Merrick

On a unix/linux machine, if I had a program that was writing output to a file and I wanted to monitor its progress, I'd use tail -f...
I would like to do essentially the same thing in an app: monitor the output of another program (which is being written to file) but have it appear in a text window in the monitoring app. I can only assume there is an SDK function (or set of functions) that enable this. Can anyone tell me the name of the SDK function or suggest a place to start looking?

Thanks...

zooba

AFAIK, you'd have to rewrite 'tail' to get the same result. Open the file (CreateFileEx), check the length (GetFileSizeEx), skip to the newest part (SetFilePointerEx), read the new bit (ReadFile) and display it.

If the original program has requested no sharing, you won't be able to open the file until it is done.

Cheers,

Zooba :U

Ehtyar

I believe the way a lot of editors/notepad replacements handle this (at least i know notepad++ does) is using the modified timestamp (GetFileTime) of the file and comparing against the last time the editor modified the file, though zooba's method seems like a far better option.

Ehtyar.

farrier

It is a GOOD day to code!
Some assembly required!
ASM me!
With every mistake, we must surely be learning. (George...Bush)

Merrick

Hmm... It seems as though this is a little more painful than I thought.
Let me qualify it a little more.

In the most generic sense, the above approaches will function like tail. What if, however, the external program that is writing data into the file were actually launched by the monitoring program (the external program is a canned program - I don't have access to the code).
So, for instance, if you use CreateProcessA, an StartupInfo structure is supplied with a sub-field with a handle called hStdOutput. Is it possible that the program is sending data to the file via StdOutput, or is StdOutput only what's going to the console? If that's a pipe for writing to the file then it seems like one could supply the handle to, let's say, a textbox on a form and listen in. Ideally, this would not affect the output file, but if the data were completely redirected to the textbox that might not be the end of the world.

I've never done this before and I was hoping someone knew.

Thanks.

zooba

If you don't explicitly specify it, standard output is the console. So if the program displays its results on the console, you can catch it by the method you suggested.

If the process opens a file explicitly, you won't be able to do it this way.

Cheers,

Zooba :U

Merrick

Yup,

After looking at the links Farrier posted and looking into the surprisingly large array of shareware, freeware, and open source tail utilities for Win32 out there, it appears that the only way to do this is to open the file read-only and snag all or the last n-bytes of the text. And, further, that the best way to monitor the file for changes is via the directory update notification APIs along with a wait function.

Thanks all.