Read a file using a program like Notepad while the file is being written to by another program?
I've created a Windows Service application that logs continuously.
I want to inspect the current events of the service without closing it. To do this I open the log.txt
in Notepad
, but gets the message
The process cannot access the file because it is being used by another process
How can I read the log file without closing the service? After the service is closed, I can readily inspect every log entry in the file.
The file is being written by calls to fopen_s
and fprintf
, if that should be of any interest. Also, the service is programmed in C/C++
on Windows 10 64-bit
, running under SCM
with default priviledges ie LocalSystem
.
https://msdn.microsoft.com/en-us/library/z5hh6ee9.aspx and then Remarks:
Files that are opened by fopen_s and _wfopen_s are not sharable. If you require that a file be sharable, use _fsopen, _wfsopen with the appropriate sharing mode constant—for example, _SH_DENYNO for read/write sharing.
Would that be a solution?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.