The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Merrick on April 14, 2007, 10:38:51 PM

Title: SDK question
Post by: Merrick on April 14, 2007, 10:38:51 PM
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...
Title: Re: SDK question
Post by: zooba on April 15, 2007, 12:45:52 AM
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
Title: Re: SDK question
Post by: Ehtyar on April 15, 2007, 12:59:43 AM
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.
Title: Re: SDK question
Post by: farrier on April 15, 2007, 04:53:39 AM
Merrick,

Try:

http://www.masm32.com/board/index.php?topic=4701.0

and/or:

http://www.masm32.com/board/index.php?topic=4945.msg37405#msg37405

hth,

farrier
Title: Re: SDK question
Post by: Merrick on April 16, 2007, 05:38:15 PM
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.
Title: Re: SDK question
Post by: zooba on April 17, 2007, 08:19:43 AM
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
Title: Re: SDK question
Post by: Merrick on April 17, 2007, 02:42:50 PM
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.