日志文件监视器

编程入门 行业动态 更新时间:2024-10-22 04:57:27
本文介绍了日志文件监视器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否可以打开一个文本文件并读取内容,而另一个应用程序正在更新该文件,使其不会导致锁冲突?

Is is possible to open a text file and read the contents while another application is updating the file, in such a way that it does not cause a lock conflict?

我需要从一个应用程序监视日志文件,每次事件发生时由另一个应用程序更新。

I need to monitor a log file from one application which is updated by another application each time an event occurs.

我在检查文件是否正在使用中,但是在所有情况下似乎都不起作用。

I do check if the file is in use before I try to read it, but that does not seem to work in all cases.

谢谢Pieter

推荐答案

这取决于第一个应用程序如何打开该文件。

it depends on how the first app open that file.

ie when调用CreateFile API来打开一个文件,有dwShareMode参数告诉api如何打开它(如果这被赋予0,它不能从其他应用程序IIRC访问)。 否则从该文件读取应该没有问题。 如果没有错误,检查是否该文件正在打开只读你可以调用像

i.e when calling CreateFile API to open a file, there is dwShareMode param which tells the api how to open it (if this was given 0, it can't be accessed from other applications IIRC). otherwise there should be no problem with reading from that file. if im not mistaken, to check if that file is being opened read only u can call something like

CreateFile(pchar(fName), GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0) ;

更多推荐

日志文件监视器

本文发布于:2023-11-11 06:12:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577594.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:监视器   文件   日志

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!