Write to locked file regardless of lock status

2019-07-04 23:38发布

问题:

Is there a way to write to a locked file regardless of what program/process has it open?

Scenario:

  • A commercial product running as a service, locks a log file.
  • Service can not be stopped because it will impact customers.
  • Would like to inject a line at the end of the file as a marker.

Getting error: The process cannot access the file because it is being used by another process.

Is there ANY way to append a line on a locked file?

Also, afraid of breaking the lock status, as it may cause the commercial program to break.

Originally thinking batch file until finding out log file is locked. Will do powershell or whatever language can pull this off.

回答1:

No, the whole idea of the lock(ed) file is that the process that has the lock does not have to worry about other processes modifying the file, so the lock owner does not have to query the file system all the time and can do it's operations much more efficiently.
And see earlier comments by "David Schwartz" and "Ken White"